By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,107 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,107 IT Pros & Developers. It's quick & easy.

how to change the php code to asp.net code

100+
P: 254
Hi
the code written below is for calculating the number of days remain for a particular event based on the specific local time i.e. time in new york or time in london.

Expand|Select|Wrap|Line Numbers
  1. <style style="text/css">
  2.  
  3. .lcdstyle{ /*Example CSS to create LCD countdown look*/
  4. background-color:black;
  5. color:lime;
  6. font: bold 18px MS Sans Serif;
  7. padding: 3px;
  8. }
  9.  
  10. .lcdstyle sup{ /*Example CSS to create LCD countdown look*/
  11. font-size: 80%
  12. }
  13.  
  14. </style>
  15.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <script type="text/javascript">
  4. ***************************/
  5.  
  6. function cdLocalTime(container, servermode, offsetMinutes, targetdate, debugmode){
  7. if (!document.getElementById || !document.getElementById(container)) return
  8. this.container=document.getElementById(container)
  9. var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
  10. this.localtime=this.serverdate=new Date(servertimestring)
  11. this.targetdate=new Date(targetdate)
  12. this.debugmode=(typeof debugmode!="undefined")? 1 : 0
  13. this.timesup=false
  14. this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
  15. this.updateTime()
  16. }
  17.  
  18. cdLocalTime.prototype.updateTime=function(){
  19. var thisobj=this
  20. this.localtime.setSeconds(this.localtime.getSeconds()+1)
  21. setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
  22. }
  23.  
  24. cdLocalTime.prototype.displaycountdown=function(baseunit, functionref){
  25. this.baseunit=baseunit
  26. this.formatresults=functionref
  27. this.showresults()
  28. }
  29.  
  30. cdLocalTime.prototype.showresults=function(){
  31. var thisobj=this
  32. var debugstring=(this.debugmode)? "<p style=\"background-color: #FCD6D6; color: black; padding: 5px\"><big>Debug Mode on!</big><br /><b>Current Local time:</b> "+this.localtime.toLocaleString()+"<br />Verify this is the correct current local time, in other words, time zone of count down date.<br /><br /><b>Target Time:</b> "+this.targetdate.toLocaleString()+"<br />Verify this is the date/time you wish to count down to (should be a future date).</p>" : ""
  33.  
  34. var timediff=(this.targetdate-this.localtime)/1000 //difference btw target date and current date, in seconds
  35. if (timediff<0){ //if time is up
  36. this.timesup=true
  37. this.container.innerHTML=debugstring+this.formatresults()
  38. return
  39. }
  40. var oneMinute=60 //minute unit in seconds
  41. var oneHour=60*60 //hour unit in seconds
  42. var oneDay=60*60*24 //day unit in seconds
  43. var dayfield=Math.floor(timediff/oneDay)
  44. var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
  45. var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
  46. var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
  47. if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
  48. hourfield=dayfield*24+hourfield
  49. dayfield="n/a"
  50. }
  51. else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
  52. minutefield=dayfield*24*60+hourfield*60+minutefield
  53. dayfield=hourfield="n/a"
  54. }
  55. else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
  56. var secondfield=timediff
  57. dayfield=hourfield=minutefield="n/a"
  58. }
  59. this.container.innerHTML=debugstring+this.formatresults(dayfield, hourfield, minutefield, secondfield)
  60. setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
  61. }
  62.  
  63. /////CUSTOM FORMAT OUTPUT FUNCTIONS BELOW//////////////////////////////
  64.  
  65. //Create your own custom format function to pass into cdLocalTime.displaycountdown()
  66. //Use arguments[0] to access "Days" left
  67. //Use arguments[1] to access "Hours" left
  68. //Use arguments[2] to access "Minutes" left
  69. //Use arguments[3] to access "Seconds" left
  70.  
  71. //The values of these arguments may change depending on the "baseunit" parameter of cdLocalTime.displaycountdown()
  72. //For example, if "baseunit" is set to "hours", arguments[0] becomes meaningless and contains "n/a"
  73. //For example, if "baseunit" is set to "minutes", arguments[0] and arguments[1] become meaningless etc
  74.  
  75. //1) Display countdown using plain text
  76. function formatresults(){
  77. if (this.timesup==false){//if target date/time not yet met
  78. var displaystring="<span style='background-color: #CFEAFE'>"+arguments[1]+" hours "+arguments[2]+" minutes "+arguments[3]+" seconds</span> left until launch time"
  79. }
  80. else{ //else if target date/time met
  81. var displaystring="Launch time!"
  82. }
  83. return displaystring
  84. }
  85.  
  86. //2) Display countdown with a stylish LCD look, and display an alert on target date/time
  87. function formatresults2(){
  88. if (this.timesup==false){ //if target date/time not yet met
  89. var displaystring="<span class='lcdstyle'>"+arguments[0]+" <sup>days</sup> "+arguments[1]+" <sup>hours</sup> "+arguments[2]+" <sup>minutes</sup> "+arguments[3]+" <sup>seconds</sup></span> left until launch time"
  90. }
  91. else{ //else if target date/time met
  92. var displaystring="" //Don't display any text
  93. alert("Launch time!") //Instead, perform a custom alert
  94. }
  95. return displaystring
  96. }
  97.  
  98. </script>
  99.  
Expand|Select|Wrap|Line Numbers
  1.     <title>Untitled Page</title>
  2. </head>
  3. <body>
  4.     <form id="form1" runat="server">
  5.     <div id="cdcontainer"></div>
  6.  
  7. <script type="text/javascript">
  8. //cdLocalTime("ID_of_DIV_container", "server_mode", LocaltimeoffsetMinutes, "target_date", "opt_debug_mode")
  9. //cdLocalTime.displaycountdown("base_unit", formatfunction_reference)
  10.  
  11. //Note: "launchdate" should be an arbitrary but unique variable for each instance of a countdown on your page:
  12.  
  13. var launchdate=new cdLocalTime("cdcontainer", "server-php", 0, "April 23, 2010 15:53:00", "debugmode")
  14. launchdate.displaycountdown("days", formatresults2)
  15. </script>
  16.     </form>
  17.  

in the above code how can I change the line var servertimestring=(servermode=="server-php")....... which is a php scripting and I want to change it to asp.net code so that I can run it.

how can I do it?
Nov 23 '09 #1
Share this Question
Share on Google+
10 Replies

Plater
Expert 5K+
P: 7,872
All I saw was javascript code there
Nov 24 '09 #2

100+
P: 254
in that javascript code some php code is also written at line 9 and when I run this code in .net it gives error and that is of php so i wanted to change/modify so that i can run/use this without error
Nov 25 '09 #3

Plater
Expert 5K+
P: 7,872
Ok so it's just this line:
var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'

I'm not sure what that line does, just print the time in a specific format?
Nov 25 '09 #4

Frinavale
Expert Mod 5K+
P: 9,731
If that's the only line of PhP code that has to be converted to ASP.NET then you would probably just do something like:

var servertimestring=(servermode=="server-php")? '<%= theDate.ToString("dd/yyyy HH:mm:ss") %> : (servermode=="server-ssi")?'<%= Now() %>'

Mind you this line doesn't make sense to me..... but I think you get the point.
Nov 25 '09 #5

Markus
Expert 5K+
P: 6,050
Hm, I don't see why you need either language. You're already using SSI, so why not use it in place of the PHP / ASP.NET?
Nov 25 '09 #6

100+
P: 254
but when I run this code it gives following error
Compiler Error Message: CS0103: The name 'Now' does not exist in the current context

so what i need to change in this code to run it correctly.
Nov 26 '09 #7

100+
P: 254
what is theDate.ToString here means where you have defined this?
Nov 26 '09 #8

Frinavale
Expert Mod 5K+
P: 9,731
"theDate" is a DateTime variable that contains the date.
theDate.ToString returns the string version of the date so that it can be displayed in a way that makes sense to people (dates are stored as numbers usually)

-Frinny
Nov 26 '09 #9

100+
P: 254
but it gives the error Compiler Error Message: CS0103: The name 'Now' does not exist in the current context
Nov 27 '09 #10

Frinavale
Expert Mod 5K+
P: 9,731
Try using DateTime.Now.
Nov 27 '09 #11

Post your reply

Sign in to post your reply or Sign up for a free account.