Appending Date/Time Stamp to filename

D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sun, 26 Sep 2004 07:04:22, seen in Don
function datetimestamp()
{
var today = new Date();
var sToday = (today.getMonth()+1).toString();
sToday += today.getDate().toString();
sToday += today.getYear().toString();
sToday += today.getHours().toString();
sToday += today.getMinutes().toString();
sToday += today.getSeconds().toString();
return sToday;
}

The concatenation is more effectively done as

var sToday = "" +
today.getMonth()+1) +
today.getDate() +
today.getYear() +
today.getHours() +
today.getMinutes() +
today.getSeconds() ;

Unless you use field separators or leading zeroes or both, the result
will be horribly ambiguous if M<10 xor D<10, or any but not all of h m s
<10 (that assumes the year to be recognisable).

FFF is unwise for general use; follow FIPS 4.1 (if American) or ISO
8601.

The following gives a universally comprehensible result, and, after
thinking about it for the first time, will seem far simpler.

with (new Date()) sToday = ((((
getYear()*100 + (getMonth()+1))*100 + getDate())*100 +
getHours())*100 + getMinutes())*100 + getSeconds()

For leading zeroes AND separators, use <FAQENTRY>

function LZ(x) { return (x<0||x>=10?"":"0") + x }


*** DO NOT MULTI-POST ***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top