473,729 Members | 2,359 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 servertimestrin g=(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 2774
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 servertimestrin g=(servermode== "server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="s erver-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 servertimestrin g=(servermode== "server-php")? '<%= theDate.ToStrin g("dd/yyyy HH:mm:ss") %> : (servermode=="s erver-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.ToStrin g 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.ToStrin g 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

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

Similar topics

8
9196
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 a namespace and another typedef to basic_string: namespace my_string {
12
3051
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 when CurrentUser() <> "xx" I just noticed that the property's can only be changed changed by a user belonging to 'Admins'. I never noticed this before. I could swear that in other apps (A97) this works fine without the user being an admin... ...
3
5011
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 data in the text boxes. Then an "update" button saves the data back to the database. What is the best way to change several properties on most of the textbox controls on the form when the "modify" button is clicked? (e.g. make them editible (and...
5
7872
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 change things outside of the cell ranges. I will try and post in an Excel group, but i do not need to change it in a worksheet, I need to change it through a VB application. For example, I am using this code to change values in certain cells: ...
11
7454
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
9404
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
30959
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
2223
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 with 2.6 it raised type B, and further, there was no string value for the exception. I tracked this down to the C code incorrectly returning Py_None when it should have returned NULL. Changing the C code to return NULL made it behave correctly...
15
3722
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 element in Firefox.
2
5076
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 ChangePasswordAD(string strLogin, string strOldPasswd, string strNewPasswd) { try { string domainAndUsername = "aloha.com" + @"\" + strLogin; DirectoryEntry entry = new...
0
8921
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.