Skip to content

Instantly share code, notes, and snippets.

@fbukevin
Created May 13, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbukevin/e68de650a09806eec2c6b5cbdaa96e19 to your computer and use it in GitHub Desktop.
Save fbukevin/e68de650a09806eec2c6b5cbdaa96e19 to your computer and use it in GitHub Desktop.
var TimeTool = {
// _year: '1997',
// _month: '01',
// _date: '01',
// _hour: '00',
// _minute: '00',
// _second: '00',
getTime: ()=>{
var date = new Date();
_year = date.getFullYear()
_month = date.getMonth() + 1 // Node.js 的 getMonth 是 0 ~ 11 對應 Jan ~ Dec
_date = date.getDate()
_hour = date.getHours()
_minute = date.getMinutes()
_second = date.getSeconds()
return _year + "/" + _month + "/" + _date + " " + _hour + ":" + _minute + ":" + _second
},
getDeadline: (days)=>{
/*
* 2 個月 = 60 * 24 * 60 * 60 = 5,184,000 seconds = 5,184,000,000 milliseconds
*/
var deadline = new Date(Date.now() + days * 24 * 60 * 60 * 1000)
_year = deadline.getFullYear()
_month = deadline.getMonth() + 1 // Node.js 的 getMonth 是 0 ~ 11 對應 Jan ~ Dec
_date = deadline.getDate()
_hour = deadline.getHours()
_minute = deadline.getMinutes()
_second = deadline.getSeconds()
return _year + "/" + _month + "/" + _date + " " + _hour + ":" + _minute + ":" + _second
},
getDue: (days) =>{
/*
* 90 * 24 * 60 * 60 = 7,776,000 seconds = 7,776,000,000 milliseconds
*/
var deadline = new Date(Date.now() + days * 24 * 60 * 60 * 1000)
_year = deadline.getFullYear()
_month = deadline.getMonth() + 1 // Node.js 的 getMonth 是 0 ~ 11 對應 Jan ~ Dec
_date = deadline.getDate()
return _year + "/" + _month + "/" + _date
},
parseDateTime: (dateTime)=>{
// 將 "2016/12/18 12:9:2" 分解成 _year, _month, _date, _hour, _minute, _second
},
parseDate: (date)=>{
// 將 "2016/12/18" 分解成 _year, _month, _date
}
}
module.exports = TimeTool;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment