473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

getting GMT in a particular format

Hi,
I want to get gmt in the format "MM/DD/YY HR:MIN:SEC". I have
written the following code. Could any one of you suggest a better
way ?

var localTime = new Date();
var utc = localTime.getTime() +
(localTime.getTimezoneOffset() * 60000 );
var currTime = new Date(utc); //gmt time

var month = AppendLeadingZero(currTime.getMonth() + 1);
var date = AppendLeadingZero(currTime.getDate());
var hours = AppendLeadingZero(currTime.getHours());
var year = currTime.getFullYear().toString().substr(2,2);
var minutes = AppendLeadingZero(currTime.getMinutes());
var seconds = AppendLeadingZero(currTime.getSeconds());
var gmt = month + "/" + date + "/" + year + " " + hours + ":"
+ minutes + ":" + seconds;

Is there any better way in javascript to get gmt in this format ?

Thanks In Advance
Kiran.

Sep 5 '07 #1
4 4151
wolverine wrote on 05 sep 2007 in comp.lang.javascript:

I want to get gmt in the format "MM/DD/YY HR:MIN:SEC".
Are you "into" ancient defective forms of date notation?
I have
written the following code. Could any one of you suggest a better
way ?

var localTime = new Date();
var utc = localTime.getTime() +
(localTime.getTimezoneOffset() * 60000 );
var currTime = new Date(utc); //gmt time

var month = AppendLeadingZero(currTime.getMonth() + 1);
var date = AppendLeadingZero(currTime.getDate());
var hours = AppendLeadingZero(currTime.getHours());
var year = currTime.getFullYear().toString().substr(2,2);
var minutes = AppendLeadingZero(currTime.getMinutes());
var seconds = AppendLeadingZero(currTime.getSeconds());
This gives you the current UTC time in a string:

function t(x){return ((x>9)?'':'0')+x};

d = new Date();
var UTCtime =
t(d.getUTCHours()) + ':' +
t(d.getUTCMinutes()) + ':' +
t(d.getUTCSeconds());

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '07 #2
In comp.lang.javascript message <11*********************@w3g2000hsg.goog
legroups.com>, Wed, 5 Sep 2007 04:36:26, wolverine
<ki*********@gmail.composted:
I want to get gmt in the format "MM/DD/YY HR:MIN:SEC". I have
written the following code. Could any one of you suggest a better
way ?
That's a silly way to write a date. The International Standard, and
common sense, calls for YYYY-MM-DD HH:MM:SS. But for the USA, surely
you need the 12-hour clock?
>var localTime = new Date();
var utc = localTime.getTime() +
(localTime.getTimezoneOffset() * 60000 );
var currTime = new Date(utc); //gmt time

var month = AppendLeadingZero(currTime.getMonth() + 1);
var date = AppendLeadingZero(currTime.getDate());
var hours = AppendLeadingZero(currTime.getHours());
var year = currTime.getFullYear().toString().substr(2,2);
var minutes = AppendLeadingZero(currTime.getMinutes());
var seconds = AppendLeadingZero(currTime.getSeconds());
var gmt = month + "/" + date + "/" + year + " " + hours + ":"
+ minutes + ":" + seconds;

Is there any better way in javascript to get gmt in this format ?
For the present purpose, GMT is now called UTC. To build a UTC
date/time, use the UTC methods.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 5 '07 #3
On Sep 5, 10:25 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
wolverine wrote on 05 sep 2007 in comp.lang.javascript:
I want to get gmt in the format "MM/DD/YY HR:MIN:SEC".

Are you "into" ancient defective forms of date notation?
I have
written the following code. Could any one of you suggest a better
way ?
var localTime = new Date();
var utc = localTime.getTime() +
(localTime.getTimezoneOffset() * 60000 );
var currTime = new Date(utc); //gmt time
var month = AppendLeadingZero(currTime.getMonth() + 1);
var date = AppendLeadingZero(currTime.getDate());
var hours = AppendLeadingZero(currTime.getHours());
var year = currTime.getFullYear().toString().substr(2,2);
var minutes = AppendLeadingZero(currTime.getMinutes());
var seconds = AppendLeadingZero(currTime.getSeconds());

This gives you the current UTC time in a string:

function t(x){return ((x>9)?'':'0')+x};

d = new Date();
var UTCtime =
t(d.getUTCHours()) + ':' +
t(d.getUTCMinutes()) + ':' +
t(d.getUTCSeconds());

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Thanks for the answer. But i expected single function to give a UTC
time in any particular format (say YYYY-MM-DD HH:MM:SS).

Once again THANKS a LOT.

Sep 6 '07 #4
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Wed, 5 Sep 2007 17:25:11, Evertjan. <ex**************@interxnl.net>
posted:
>
This gives you the current UTC time in a string:
It seems likely that new Date().toUTCString().match(/\S{8}/) will
always give that (in an Object); but it's not guaranteed by spec.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
For news:borland.*, use their server newsgroups.borland.com ; but first read
Guidelines <URL:http://www.borland.com/newsgroups/guide.htmlff. with care.
Sep 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gmanuel | last post by:
I want from VBA, be able to read what the host name of a text file is. For example, if the file passed to the function is on a particular server, I want to retrieve the name of the server it...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
1
by: anamika | last post by:
I want a report in excel from my SQL database from one table. I want to create a view and then use DTS package to export it to excel format. But how can i get the following format in a view?? They...
7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
3
by: James | last post by:
Hello group, I've got an application that works just fine as an mdb file, but I've been running most of my production apps as mde files. When I convert a particular database I have to mde...
7
by: Brad Quinn | last post by:
Is there a way to get the values of the paramaters to a method programatically? I know that I can use reflection to find out the parameter names and types, etc., but I want to know the values...
1
by: Oleg Shnayderman | last post by:
Hi All, I am very new to C# as well as to SQL. I need to write an application which is connecting to SQL DB and getting all the user's tables and after create a dataset for all the tables in the...
2
by: tbramley | last post by:
Hi, I've been trying to import a spreadsheet from excel into access but the way it is downloaded from the site we use to review our performance some cells are like the following: The cell shows...
4
by: sriram | last post by:
Hello Friends, I am new to this group so big HIIIIIIII to all :) fine i have a serious doubt about session handling in PHP. After 20 min (default time) session getting expired, session values...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.