Created
August 8, 2012 10:38
-
-
Save itsjavi/3294132 to your computer and use it in GitHub Desktop.
js date tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datetools = { | |
"inDateRange":function(date, time_from, time_to){ | |
if(isNaN(time_from) || isNaN(time_to)){ | |
return false; | |
} | |
var dfrom = new Date(parseInt(time_from)*1000); | |
var dto = new Date(parseInt(time_to)*1000); | |
dto = new Date(dto.getFullYear(), dto.getMonth(), dto.getDate(), 23, 59, 59); | |
var now = date.getTime(); | |
return (now >= dfrom.getTime()) && (now <= dto.getTime()); | |
}, | |
"strToDate":function(str){ | |
var t = str.split(/[- :]/); | |
return new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]); | |
}, | |
"strToTime":function(str){ | |
return this.strToDate(str).getTime(); | |
}, | |
"dateToStr":function(date, hms){ | |
hms = hms || " 00:00:00"; | |
return ('0' + date.getDate()).slice(-2) + '/' | |
+ ('0' + (date.getMonth()+1)).slice(-2) + '/' | |
+ date.getFullYear() + hms; | |
}, | |
"timeToStr":function(time, hms){ | |
return this.dateToStr(new Date(time), hms); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment