N
Nige
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="JavaScript">
function ShowDateTime()
{
var today = new Date();
var mo=today.getMonth()+1;
var da=today.getDate();
var ho=today.getHours();
var mi=today.getMinutes();
# 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!
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="JavaScript">
function ShowDateTime()
{
var today = new Date();
var mo=today.getMonth()+1;
var da=today.getDate();
var ho=today.getHours();
var mi=today.getMinutes();
# 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!