Last active
December 1, 2016 05:31
-
-
Save ZZR-china/9af11bb2557e04633c2e68d602adfa34 to your computer and use it in GitHub Desktop.
a simple moment.js demo
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
const moment = require('moment'), | |
localTime = require('moment-timezone'); | |
const timeHelp = { | |
//Returns the current time in Shanghai time zone | |
timeShanghai: function () { | |
return localTime.tz(moment(), "Asia/Shanghai").format("YYYY-MM-DD HH:mm"); | |
}, | |
//Passes in a UNIX time value, converts to local Shanghai Time, and returns the value | |
unixToShanghaiTime: function (unixTime) { | |
return localTime.tz(moment.unix(unixTime),"Asia/Shanghai") | |
.format("YYYY-MM-DD HH:mm"); | |
}, | |
//Pass in a Unix timestamp (from the past), calculate how many minutes has elapsed | |
//Return the "minutes" value | |
howOldInMinutes: function (unixTime) { | |
var currentTime = moment().unix(), | |
age = moment(moment.unix(currentTime)).diff(moment.unix(unixTime), 'minutes'); | |
return age; | |
}, | |
hasExpired: function () { | |
var currentDateTime = moment().unix(); | |
return currentDateTime; | |
} | |
}; | |
module.exports = timeHelp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment