472,328 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

how to change the php code to asp.net code

254 100+
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
10 2590
Plater
7,872 Expert 4TB
All I saw was javascript code there
Nov 24 '09 #2
mukeshrasm
254 100+
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
7,872 Expert 4TB
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
9,735 Expert Mod 8TB
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
6,050 Expert 4TB
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
mukeshrasm
254 100+
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
mukeshrasm
254 100+
what is theDate.ToString here means where you have defined this?
Nov 26 '09 #8
Frinavale
9,735 Expert Mod 8TB
"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
mukeshrasm
254 100+
but it gives the error Compiler Error Message: CS0103: The name 'Now' does not exist in the current context
Nov 27 '09 #10
Frinavale
9,735 Expert Mod 8TB
Try using DateTime.Now.
Nov 27 '09 #11

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

Similar topics

8
by: Patrick Kowalzick | last post by:
Dear NG, I would like to change the allocator of e.g. all std::strings, without changing my code. Is there a portable solution to achieve this? ...
12
by: Arno R | last post by:
Hi there, I just distributed an application in which I (try to) change db.properties depending on CurrentUser() For instance I set the property's...
3
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you...
5
by: Elena | last post by:
I need the VB.NET code to change the header/footer of an Excel spread sheet, ASAP. I am doing it through a VB application. I can change the...
11
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
3
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RecordSource of a Master Report is: Me.RecordSource = "TableOrQueryName"
25
by: Peng Yu | last post by:
Hi, It is possible to change the length of "\t" to a number other than 8. std::cout << "\t"; Thanks, Peng
4
by: Heikki Toivonen | last post by:
I was debugging M2Crypto function written in C which changed behavior between Python 2.6 and earlier Python versions. In an error condition the...
15
by: Sunny | last post by:
Hi, I can change the lement opacity in IE using. abc.style.filter = 'alpha(opacity=' + 10 + ')'; But this dont work in firefox, In firefox it...
2
by: bemytthm | last post by:
I just want to ask abt communicate with AD using ASP.net. I would want to ask you all to help me correct a problem like this: This is a code i use...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.