Wednesday 8 June 2011

Simple JavaScript function to create TimeStamp from Date()

function dateTimeStamp()
{
return (new Date().toLocaleString()+':'+new Date().getMilliseconds());
}

if you call the above method output will be something like
08 June 2011 17:29:04:605

toLocaleString()
Converts a Date object to a string, using locale conventions

getMilliseconds()
Returns the milliseconds (from 0-999)

If you are looking for a milliseconds version of the Date objects then you have to use Date.getTime() which returns the number of milliseconds since midnight Jan 1, 1970.

Click here for a complete list of JavaScript Date Object Methods

No comments:

Post a Comment