473,506 Members | 16,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to change the php code to asp.net code

254 Contributor
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 2741
Plater
7,872 Recognized Expert Expert
All I saw was javascript code there
Nov 24 '09 #2
mukeshrasm
254 Contributor
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 Recognized Expert Expert
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 Recognized Expert Moderator Expert
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 Recognized Expert Expert
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 Contributor
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 Contributor
what is theDate.ToString here means where you have defined this?
Nov 26 '09 #8
Frinavale
9,735 Recognized Expert Moderator Expert
"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 Contributor
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 Recognized Expert Moderator Expert
Try using DateTime.Now.
Nov 27 '09 #11

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

Similar topics

8
9163
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? The only nice solution I can think of, would be...
12
3035
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 AllowBypassKey and AllowBuiltinToolbars to False...
3
4980
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 click a "modify" button you are allowed to change...
5
7860
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 ranges/cell values using code, but I do not know how to...
11
7432
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
9367
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
30789
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
2210
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 function was supposed to raise exception type A, but...
15
3693
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 throws error. How I can change the opacity of an...
2
5068
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 to change password on AD public bool...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.