Time
-
Close, but not quite. I am sure it is just typos but what is
m
supposed to be, month or minute? Also the month is displayed as three letters, not a two digit number. Also I agree with David, you should get the local timezone from the local machine, not from the user's profile. Just one less thing for the server to do. [edit] Also, not all time zones are full hours off of UTC. Newfoundland is -3.5. [/edit] [edit2] Do not forget about daylight savings. This is going to be more difficult then spending two minutes to slap together a small script. But keep working at it, it is avery good idea. [/edit2]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
the first "bug's" are solved look here http://xwega.com/codeproject/timezone.asp[^] PJ Arends wrote: Also, not all time zones are full hours off of UTC. Newfoundland is -3.5. i think this is done also , because now i'm usin the get getTimezoneOffset() that return the value in minutes and calculating the correct time using minutes instead of hours PJ Arends wrote: Do not forget about daylight savings Any idea on how to calculate this?
-
Close, but not quite. I am sure it is just typos but what is
m
supposed to be, month or minute? Also the month is displayed as three letters, not a two digit number. Also I agree with David, you should get the local timezone from the local machine, not from the user's profile. Just one less thing for the server to do. [edit] Also, not all time zones are full hours off of UTC. Newfoundland is -3.5. [/edit] [edit2] Do not forget about daylight savings. This is going to be more difficult then spending two minutes to slap together a small script. But keep working at it, it is avery good idea. [/edit2]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
I dont need to think of time zones or even daylight saving... All i need is to get the date diff from server and client and apply that date diff to the date in question.
function ConvertTime(svrdate,anydate) { clientDate = new Date(); serverDate = new Date(svrdate); date = new Date(anydate); datediff = (clientDate.valueOf()-serverDate.valueOf())/1000/60; //minutes date.setMinutes(date.getMinutes()+datediff); //the convertion h = date.getHours(); n = date.getMinutes(); sTime = h+":"+((n<10)?"0"+n:n)+" "; sDate = new String(date.toUTCString()); //because string allways have the same format i place hardcoded values instead of making a search sDate = sDate.substr(5,6); sDate+=" '"+(String(date.getFullYear()).substr(2,2)); sTime+=sDate; document.write(sTime); } ConvertTime("<%=Now%>","03-25-2005 17:06")
http://xwega.com/codeproject/timezone.asp[^] -
it would be cool to gave the forum posts in our own time , and i think you can doit without any server intervention. you can provide a way to configure time zone in the profile , and then show the time acording using only client side script servers would not feel a thing
Max Santos wrote: you can provide a way to configure time zone in the profile That already exists, in fact Chris put that setting there just for the purpose you suggest. But since I see you're working on some script, I wanted to point out that the user's time zone is already available. --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD
-
Max Santos wrote: you can provide a way to configure time zone in the profile That already exists, in fact Chris put that setting there just for the purpose you suggest. But since I see you're working on some script, I wanted to point out that the user's time zone is already available. --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD
done ! i have reworked the script. thing is done, can you give it a try?. I dont need to think of time zones or even daylight saving... All i need is to get the date diff from server and client and apply that date diff to the date in question.
function ConvertTime(svrdate,anydate) { clientDate = new Date(); serverDate = new Date(svrdate); date = new Date(anydate); datediff = (clientDate.valueOf()-serverDate.valueOf())/1000/60; //minutes date.setMinutes(date.getMinutes()+datediff); //the convertion d = date.getDate(); m = date.getMonth()+1; h = date.getHours(); n = date.getMinutes(); sTime = h+":"+((n<10)?"0"+n:n)+" "; sDate = new String(date.toUTCString()); //because string allways have the same format i place hardcoded values instead of making a search sDate = sDate.substr(5,6); sDate+=" '"+(String(date.getFullYear()).substr(2,2)); sTime+=sDate; document.write(sTime); } ConvertTime("<%=Now%>","03-25-2005 17:06")
http://xwega.com/codeproject/timezone.asp[^] -
I dont need to think of time zones or even daylight saving... All i need is to get the date diff from server and client and apply that date diff to the date in question.
function ConvertTime(svrdate,anydate) { clientDate = new Date(); serverDate = new Date(svrdate); date = new Date(anydate); datediff = (clientDate.valueOf()-serverDate.valueOf())/1000/60; //minutes date.setMinutes(date.getMinutes()+datediff); //the convertion h = date.getHours(); n = date.getMinutes(); sTime = h+":"+((n<10)?"0"+n:n)+" "; sDate = new String(date.toUTCString()); //because string allways have the same format i place hardcoded values instead of making a search sDate = sDate.substr(5,6); sDate+=" '"+(String(date.getFullYear()).substr(2,2)); sTime+=sDate; document.write(sTime); } ConvertTime("<%=Now%>","03-25-2005 17:06")
http://xwega.com/codeproject/timezone.asp[^]Looks good, but make sure you test it with a bunch of different dates (ie over new years, leap years, etc) to make sure all the bugs are out. Then maybe email it directly to Chris and see if he wants to go through the effort of integrating it.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Honoured as one of The Most Helpful Members of 2004
-
I dont need to think of time zones or even daylight saving... All i need is to get the date diff from server and client and apply that date diff to the date in question.
function ConvertTime(svrdate,anydate) { clientDate = new Date(); serverDate = new Date(svrdate); date = new Date(anydate); datediff = (clientDate.valueOf()-serverDate.valueOf())/1000/60; //minutes date.setMinutes(date.getMinutes()+datediff); //the convertion h = date.getHours(); n = date.getMinutes(); sTime = h+":"+((n<10)?"0"+n:n)+" "; sDate = new String(date.toUTCString()); //because string allways have the same format i place hardcoded values instead of making a search sDate = sDate.substr(5,6); sDate+=" '"+(String(date.getFullYear()).substr(2,2)); sTime+=sDate; document.write(sTime); } ConvertTime("<%=Now%>","03-25-2005 17:06")
http://xwega.com/codeproject/timezone.asp[^]Wow, looks very good. I appreciate the effort you put into this :-) Nish
-
Wow, looks very good. I appreciate the effort you put into this :-) Nish
thank you. Very nice to ear it. Any chance this end up on the CodeProject boards some day? :-D
-
it would be cool to gave the forum posts in our own time , and i think you can doit without any server intervention. you can provide a way to configure time zone in the profile , and then show the time acording using only client side script servers would not feel a thing
The timezone is already inplace in the profile but updating the timestamp everywhere in the site where a time is displayed hasn't been done because there are other items I feel a more important. It's far, far easier simply to calculate an offset based on the reader's timezone and the server's timezone and then do
DateTime RelativeDate = AbsoluteDate.AddHours(Offset);
return RelativeDate.ToShortTimeString();cheers, Chris Maunder
-
The timezone is already inplace in the profile but updating the timestamp everywhere in the site where a time is displayed hasn't been done because there are other items I feel a more important. It's far, far easier simply to calculate an offset based on the reader's timezone and the server's timezone and then do
DateTime RelativeDate = AbsoluteDate.AddHours(Offset);
return RelativeDate.ToShortTimeString();cheers, Chris Maunder
i started to make a script using timezons ,but a very big problem came up (lightsaving). Chris Maunder wrote: simply to calculate an offset based on the reader's yes it is , but you can do it all on the client side, less for the servers to do. and in case you did not take a look at my previus posts on this thread :D here it is: and one optimization can be made: istead of sending the servertime to the function everytime , you can declare it inside the fuction, avoiding to much calls to "Now" on the server.
function ConvertTime(svrdate,anydate) { clientDate = new Date(); serverDate = new Date(svrdate); date = new Date(anydate); datediff = (clientDate.valueOf()-serverDate.valueOf())/1000/60; //minutes date.setMinutes(date.getMinutes()+datediff); //the convertion h = date.getHours(); n = date.getMinutes(); sTime = h+":"+((n<10)?"0"+n:n)+" "; sDate = new String(date.toUTCString()); //because string allways have the same format i place hardcoded values instead of making a search sDate = sDate.substr(5,6); sDate+=" '"+(String(date.getFullYear()).substr(2,2)); sTime+=sDate; document.write(sTime); } ConvertTime("<%=Now%>","03-25-2005 17:06")
it works: http://xwega.com/codeproject/timezone.asp[^] -
it would be cool to gave the forum posts in our own time , and i think you can doit without any server intervention. you can provide a way to configure time zone in the profile , and then show the time acording using only client side script servers would not feel a thing
Why not displaying the server clock with javascript? There could be multiple settings, e.g. a digital clock or analog clock. Don't try it, just do it! ;-)