<script type= "Text/javascript" >
Replace string
function Replace (str, from, to) {
Return Str.split (from). Join (to);
}
The date type is formatted as a specified string
function formatdate (date, format) {
format = Replace (format, "yyyy", date.getfullyear ());
format = Replace (format, "MM", Getfullmonth (date));
format = Replace (format, "DD", getfulldate (date));
format = Replace (format, "HH", Getfullhour (date));
return format;
}
JS Date string converted to date type
function Parsedate (DATESTR) {
return new Date (Replace (Datestr, "-", "/"));
}
Increase month
function AddMonths (date, value) {
Date.setmonth (Date.getmonth () + value);
return date;
}
Increase Day
function AddDays (date, value) {
Date.setdate (date.getdate () + value);
return date;
}
When added
function AddHours (date, value) {
Date.sethours (date.gethours () + value);
return date;
}
Return month (two digits)
function Getfullmonth (date) {
var v = date.getmonth () + 1;
if (V > 9) return v.tostring ();
Return "0" + V;
}
Return day (two digits)
function Getfulldate (date) {
var v = date.getdate ();
if (V > 9) return v.tostring ();
Return "0" + V;
}
return time (two digits)
function Getfullhour (date) {
var v = date.gethours ();
if (V > 9) return v.tostring ();
Return "0" + V;
}
Comparison of two time
function Comparedate () {
var mydate = AddDays (Parsedate ("2012-08-23"), 1);
var nowdate = new Date ();
if (Nowdate.gettime () < Mydate.gettime ()) {
Return FormatDate (nowdate, "yyyy-mm-dd");
}
Return FormatDate (mydate, "yyyy-mm-dd");
}
</script>
The JS date function used in the project