I'm a complete novice to JS. I want to insert the date and time into a
document in the format:
WB-MMDDHHmm
Where:
WB- is a fixed string prefix (the whole string is a reference number)
MM is the month 01 to 12, with a leading 0 if required
DD is the day 01 to 31, with a leading 0 if required
HH is the hour 00 to 23, with a leading 0 if required
mm is the minute 00 to 59, with a leading 0 if required
I've got this far:
<script language="JavaS cript">
function ShowDateTime()
{
var today = new Date();
var mo=today.getMon th()+1;
var da=today.getDat e();
var ho=today.getHou rs();
var mi=today.getMin utes();
# parse here #
document.write( "WB-"+mo+da+ho+ mi);
}
</script>
The problem is the bit to parse the strings, I've tried
if (mo.length < 2) mo="0"+mo; ... etc
but it doesn't work.
Help!
--
Nige
Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat
document in the format:
WB-MMDDHHmm
Where:
WB- is a fixed string prefix (the whole string is a reference number)
MM is the month 01 to 12, with a leading 0 if required
DD is the day 01 to 31, with a leading 0 if required
HH is the hour 00 to 23, with a leading 0 if required
mm is the minute 00 to 59, with a leading 0 if required
I've got this far:
<script language="JavaS cript">
function ShowDateTime()
{
var today = new Date();
var mo=today.getMon th()+1;
var da=today.getDat e();
var ho=today.getHou rs();
var mi=today.getMin utes();
# parse here #
document.write( "WB-"+mo+da+ho+ mi);
}
</script>
The problem is the bit to parse the strings, I've tried
if (mo.length < 2) mo="0"+mo; ... etc
but it doesn't work.
Help!
--
Nige
Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat
Comment