473,387 Members | 1,492 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,387 software developers and data experts.

Date object

Hi all,

Need some help here.

How do i create a javascript date object with the format (yyyy:mm:dd
hh:mm:ss)

do i need to parse it to achieve that?

appreciate any inputs

May 8 '06 #1
13 2983
ah*****@gmail.com wrote:
Hi all,

Need some help here.

How do i create a javascript date object with the format (yyyy:mm:dd
hh:mm:ss)

do i need to parse it to achieve that?

appreciate any inputs


Hi,

It is not clear to me what you cannot achieve.

Basically you need to do 2 things:
1) Know how to make a date
2) Know how to break up your example String representation of a date.

1) according to the API:
var myDate = new Date(year,month,day,hour,minutes,seconds,milliseco nds);

2) break up a (date)string:
var myStringDate = "1999:01:23:01:30:12";
var myDateParts = myStringDate.split(":");

You now have an array myDateParts with all the substrings, splitted on :
So myDateParts[0] contains the year, myDateParts[1] the month, etc.

Hope that helps you going.

Regards,
Erwin Moller
May 8 '06 #2
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)

I was thinking if i write my own function to achieve 2006-05-08
21:51:31 ?

May 8 '06 #3
ah*****@gmail.com wrote:
How do i create a javascript date object with the format (yyyy:mm:dd
hh:mm:ss)
do i need to parse it to achieve that?


Yes. You can use a regular expression to solve this specific case, or you
can use a lib like my date library if you wish:
http://www.javascripttoolbox.com/lib/date/

Using the lib approach you would just do:

var date = Date.parseString("2006:05:08:01:02:03","y:M:d:h:m: s");

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 8 '06 #4
ah*****@gmail.com said the following on 5/8/2006 9:52 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<URL: http://www.safalra.com/special/googlegroupsreply/ >
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)
OK.
I was thinking if i write my own function to achieve 2006-05-08
21:51:31 ?


There was a brief explanation given on how the Date object works and
hints on how to start writing the code.
Although the example was the other way around.

var now = new Date();
document.write('Day of Week is now.getDay and gives: '
+ now.getDay() + '<br>');

Remember that the numbers it returns are zero based. You can find all
the Date components at:

<URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/ce2202bb-7ec9-4f5a-bf48-3a04feff283e.asp>

At the very bottom.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 8 '06 #5
im trying a simple example but it is just not working

var curdate = new Date();
document.write( curdate );
document.write( curdate.getYear() );

1st Output -> Mon May 08 2006 23:28:29 GMT+0800 (China Standard Time)
2nd Output -> 106

What is wrong here?

Thanks Matt for the advice earlier on

May 8 '06 #6
realize i should use getFullYear() instead

case closed

thanks

May 8 '06 #7
wrote on 08 mei 2006 in comp.lang.javascript:
realize i should use getFullYear() instead

case closed


Not completely, since you are not quoting what you are talking about.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 8 '06 #8
JRS: In article <11*********************@u72g2000cwu.googlegroups. com>,
dated Mon, 8 May 2006 06:52:47 remote, seen in
news:comp.lang.javascript, ah*****@gmail.com posted :
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)

I was thinking if i write my own function to achieve 2006-05-08
21:51:31 ?


Methods giving that can be found via the newsgroup FAQ, see sig below.

You have not said whether you want civil time or UTC. Seek one of
these, where implementation is by adding a Method to the Date Object.

new Date().ISOlocalDTstr() // 2006-05-08 20:12:44
new Date().UTCstr() // 2006-05-08 19:13:16

Basics of code is readily seen in js-nclds.htm .

If your are writing only for local use, and if the local settings are
sensibly in conformity with ISO 8601, then consider

new Date().toLocaleString() // 05/08/2006 20:18:03

Note, of course, that in my system Microsoft has not got it right.

Erwin, Matt : you omitted to notice the absence of a central colon.

OP : Date Objects do not have a format, other than IEEE Double of
milliseconds from UTC 1970.0.

Randy : He wants date, not Day-of-Week. Javascript getYear, Day-of-Week
and Month are non-standard; other results are normal, without improper
use of zero.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
May 8 '06 #9
Evertjan. wrote:
wrote on 08 mei 2006 in comp.lang.javascript:
realize i should use getFullYear() instead

case closed


Not completely, since you are not quoting what you are talking about.


yes, quite annoying habbit some people have. :-/

Regards,
Erwin Moller
May 10 '06 #10
ah*****@gmail.com wrote:
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)
No, it does not. It assigns a reference to a new Date object to `myDate'.
When this reference is passed to window.alert(), the object's toString()
method is called, which returns the date in the above format.
I was thinking if i write my own function to achieve 2006-05-08
21:51:31 ?


(I cannot know what you are thinking, so please don't ask me.)

However, Date objects have several retrieval methods (their identifiers
starting with `get') that you can use to create the Date format you want.
RTFM, RTFFAQ.
PointedEars
--
Multiple exclamation marks are a sure sign of a diseased mind.
-- Terry Pratchett
May 18 '06 #11
Thomas 'PointedEars' Lahn wrote on 18 mei 2006 in comp.lang.javascript:
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)


No, it does not. It assigns a reference to a new Date object to
`myDate'. When this reference is passed to window.alert(), the
object's toString() method is called, which returns the date in the
above format.


yes.
var myDate= new Date();


myDate only holds two things:

1 the fact it is a date object.
2 the number of miliseconds since the beginning of [Javascript] time,
being 1970/1/1 00:00:000 GMT/UTC

It does not hold any format not even the timezone at creation.

Try:

var beginningOfTime = new Date(0);

alert(beginningOfTime);
// local time at beginning of GMT time
// .toString() is implied here

alert(beginningOfTime.toUTCString());
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 18 '06 #12
Thomas 'PointedEars' Lahn said the following on 5/17/2006 7:43 PM:
ah*****@gmail.com wrote:
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)


No, it does not. It assigns a reference to a new Date object to `myDate'.
When this reference is passed to window.alert(), the object's toString()
method is called, which returns the date in the above format.


Your pedantics are amusing sometimes. What is more amusing is your
ignorance at times.

And all this to reply to a dead 9 day old thread. I am impressed with
your prompt replies.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 18 '06 #13
JRS: In article <63****************@PointedEars.de>, dated Thu, 18 May
2006 01:43:06 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :
ah*****@gmail.com wrote:
at Date: 8 May 2006 06:52:47 -0700
var myDate= new Date();

This gives me the format
Mon May 08 2006 21:51:31 GMT+0800 (China Standard Time)


This thread died ten days ago. St Luke: Chapter 10, Verse 37, tail.

Your signature remains incompatible with well-established Usenet
standards such as FYI21/RFC1855. St John, Chapter 13, Verse 27.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
May 18 '06 #14

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

Similar topics

7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
2
by: Ian | last post by:
I would like to have some validation on a date field. The date format is dd/mm which is used for our financial year end. I suppose I need also consider leap years. Please can you shed some light on...
4
by: Christopher Benson-Manica | last post by:
I would like to subclass the built-in Date object to get additional functionality out of it, but the code below gives me an error something like "object is not a date object". Is there something...
26
by: sgershon | last post by:
Hi. I know this is should be a simple question. I know server-side web-programming, and never needed to use client-side scripting... until now :) I have done so far a little number of scripts...
17
by: ginkim | last post by:
Hi, I'm trying to work with the Australian date formats and javascript and it's causing me quite a headache. I have a date in a "dd/mm/yy" format. Whenever I try to retrieve that date from my...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.