943,635 Members | Top Members by Rank

Ad:
Apr 5th, 2007
0

convert date(string) to date (date time)

Expand Post »
please,help me i want to convert date(string) to date (date time), this date i make setting for day with one (constant)
to use it in database i write in html
<html>
<head>
<SCRIPT type="text/javascript">
function startDate()
{
var d=new Date()
var y=d.getYear()
var m=d.getMonth()+1
var day=1
var date=m+"/"+day+"/"+y
document.write("date is: "+date)
// OUTPUT WILL BE 4/1/2007 THIS IS STRING I NEEED IT DATETIME //
var dat=Date.parse(date);
document.write("date is: "+dat)
// OUTPUT WILL BE 1175378400000 //
// PLEASE HELP ME TO GET TRUE RESULT //
}
</SCRIPT>
</head>
<body onload="startDate()" >
</body>
</html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mohandsa is offline Offline
11 posts
since Oct 2006
Apr 6th, 2007
0

Re: convert date(string) to date (date time)

OK, it seems you posted twice this time with more detail... this should be posted to the Javascript lists rather than JSP lists... BUT, a date object, or datetime is just a long numberic value... counting (usually) seconds or militseconds sine the "Epoc" time... usually Jan, 1 1970 00:00:00...

You have actually got what you need for a database, which you do an insert SQL with passing the long value to a datetime column, depending upon the database should result int he correct DB value being saved... you are confusing, I think, human readability with machine readability...

The first one you show, your string is human readable, while the number is how the machine will see it when it is properly converted to a date object...

In Java, when we have a date object which represents a given date, the toString will show it as 2007-04-01 while we insert it into the DB as a timestamp with setTimestamp(1, date.getTime())...
The getTime() method of the Date object returns a "long" with is just a number with lots of places... this is what the DB requires to understand the time....

Peace,
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007
Jun 7th, 2007
0

Re: convert date(string) to date (date time)

hi,
how can i convert
var dat=Date.parse(date);
("dat" has 1175378400000)

dat again to date (i.e.,4/1/2007)
thanx in advance

Click to Expand / Collapse  Quote originally posted by Mohandsa ...
please,help me i want to convert date(string) to date (date time), this date i make setting for day with one (constant)
to use it in database i write in html
<html>
<head>
<SCRIPT type="text/javascript">
function startDate()
{
var d=new Date()
var y=d.getYear()
var m=d.getMonth()+1
var day=1
var date=m+"/"+day+"/"+y
document.write("date is: "+date)
// OUTPUT WILL BE 4/1/2007 THIS IS STRING I NEEED IT DATETIME //
var dat=Date.parse(date);
document.write("date is: "+dat)
// OUTPUT WILL BE 1175378400000 //
// PLEASE HELP ME TO GET TRUE RESULT //
}
</SCRIPT>
</head>
<body onload="startDate()" >
</body>
</html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vikki.v is offline Offline
1 posts
since Jun 2007
May 28th, 2010
1
Re: convert date(string) to date (date time)
var dat=Date.parse(date);
var theDate = new Date(dat);
//where dat is a long numeric sequence representing the epochmilliseconds.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ehassen is offline Offline
1 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript css background-image
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: custom Errors?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC