Created
June 10, 2019 16:53
-
-
Save tomoima525/f71344a68c77aeae1e062e08e86dc46c to your computer and use it in GitHub Desktop.
format to utc date
This file contains hidden or 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
import formatDateToUTC from '../utils/format_date_to_utc'; | |
describe('formatDateToUTC', () => { | |
test('should format date to UTC time zone', () => { | |
const date = new Date('May 9, 2019 11:33:30 GMT-07:00'); // Pacific Day Light Time | |
expect(formatDateToUTC(date)).toEqual('201905091833'); | |
}); | |
}); |
This file contains hidden or 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 formatDateToUTC = date => { | |
const month = `${date.getUTCMonth() + 1}`; | |
const day = `${date.getUTCDate()}`; | |
const hour = `${date.getUTCHours()}`; | |
const min = `${date.getUTCMinutes()}`; | |
const year = `${date.getFullYear()}`; | |
const list = [year, month, day, hour, min]; | |
return list | |
.map(v => { | |
if (v.length === 1) { | |
return `0${v}`; | |
} | |
return v; | |
}) | |
.join(''); | |
}; | |
module.exports = formatDateToUTC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment