HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Timezone Converter
Post new topic   Reply to topic    HTML Help Forum -> Javascript
View previous topic :: View next topic  
Author Message
cheekymonkey



Joined: 27 Oct 2007
Posts: 2

PostPosted: Mon Oct 29, 2007 8:38 pm     Timezone Converter Reply with quote

I can't seem to find a way to convert timezone without having it set off of my computer clock. I want a timezone converter that converts from a date/time that I enter to a date/time zone that's specificed.
I basically want it to subtract 1.5 hours from whichever date/time I enter. Does anyone know any coding for this? I can't seem to find it anywhere. I can find lots of timezone converters that convert the date/time from the computer, but that's not what I'm looking for. Thanks Smile

Time format:
10/26/2007 9:50:14 PM
kanenas



Joined: 14 Dec 2004
Posts: 341

PostPosted: Tue Dec 04, 2007 7:58 pm     Javascript's "Date" object Reply with quote

JS seems to support only UTC and local time. You could use Date.parse to create the date from a string, or roll your own date parser using the Date.set* methods (see W3 School or DevGuru's "Date" object reference for more info on the "set" methods, amoung others). Once you have a date object, you can use (e.g.) Date.getHours and Date.setHours, or getTime and Date.setTime (or Date constructor), to manually convert based on timezone. You'll have to write code to figure out the proper offset; Date.getTimezoneOffset may be of use.
Code:
var hourInMils=60 * 60 * 1000;
time2.setHours(time1.getHours() - 1.5);
time2.setTime(time1.getTime() - 1.5 * hoursInMils);

Note that setHours handles cases where adding/subtracting hours takes the time past midnight just fine (e.g. yesterday.setHours(today.getHours - 24) will set 'yesterday' to 1 day earlier than 'today').
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial