1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Cleaned up the date functions

This commit is contained in:
Jeremy Ruston 2011-11-30 18:05:20 +00:00
parent b907d846f3
commit b143194c91

View File

@ -17,12 +17,6 @@ utils.zeroPad = function(n,d)
return s;
};
// Convert a date to local YYYYMMDDHHMM string format
utils.convertToLocalYYYYMMDDHHMM = function(date)
{
return date.getFullYear() + utils.zeroPad(date.getMonth()+1,2) + utils.zeroPad(date.getDate(),2) + utils.zeroPad(date.getHours(),2) + utils.zeroPad(date.getMinutes(),2);
};
// Convert a date to UTC YYYYMMDDHHMM string format
utils.convertToYYYYMMDDHHMM = function(date)
{
@ -32,27 +26,24 @@ utils.convertToYYYYMMDDHHMM = function(date)
// Convert a date to UTC YYYYMMDD.HHMMSSMMM string format
utils.convertToYYYYMMDDHHMMSSMMM = function(date)
{
return date.getUTCFullYear() + utils.zeroPad(date.getUTCMonth()+1,2) + utils.zeroPad(date.getUTCDate(),2) + "." + utils.zeroPad(date.getUTCHours(),2) + utils.zeroPad(date.getUTCMinutes(),2) + utils.zeroPad(date.getUTCSeconds(),2) + utils.zeroPad(date.getUTCMilliseconds(),3) +"0";
return date.getUTCFullYear() + utils.zeroPad(date.getUTCMonth()+1,2) + utils.zeroPad(date.getUTCDate(),2) + utils.zeroPad(date.getUTCHours(),2) + utils.zeroPad(date.getUTCMinutes(),2) + utils.zeroPad(date.getUTCSeconds(),2) + utils.zeroPad(date.getUTCMilliseconds(),3) +"0";
};
// Create a date from a UTC YYYYMMDDHHMM format string
// Create a UTC date from a YYYYMMDDHHMM format string
utils.convertFromYYYYMMDDHHMM = function(d)
{
d = d?d.replace(/[^0-9]/g, ""):"";
return utils.convertFromYYYYMMDDHHMMSSMMM(d.substr(0,12));
};
// Create a date from a UTC YYYYMMDDHHMMSS format string
// Create a UTC date from a YYYYMMDDHHMMSS format string
utils.convertFromYYYYMMDDHHMMSS = function(d)
{
d = d?d.replace(/[^0-9]/g, ""):"";
return utils.convertFromYYYYMMDDHHMMSSMMM(d.substr(0,14));
};
// Create a date from a UTC YYYYMMDDHHMMSSMMM format string
// Create a UTC date from a YYYYMMDDHHMMSSMMM format string
utils.convertFromYYYYMMDDHHMMSSMMM = function(d)
{
d = d ? d.replace(/[^0-9]/g, "") : "";
return new Date(Date.UTC(parseInt(d.substr(0,4),10),
parseInt(d.substr(4,2),10)-1,
parseInt(d.substr(6,2),10),