feat: adding function to convert

This commit is contained in:
Carlos Gutierrez
2021-11-22 09:52:22 -06:00
parent e4a9cfd403
commit b369bcfda0
4 changed files with 47 additions and 0 deletions

26
index.js Normal file
View File

@ -0,0 +1,26 @@
const GMT = require('node-gmt')
const gmtHours = 'GMT-05:00'
const addCero = (num) => {
return num < 10 ? `0${num}` : num
}
const getDateNow = (dateGetThem) => {
const gmt = new GMT(gmtHours)
let currentDate = (!dateGetThem) ? new Date() : new Date(dateGetThem)
currentDate = gmt.relativeDate(currentDate)
const date = currentDate.getDate()
const month = currentDate.getMonth()
const year = currentDate.getFullYear()
const hour = currentDate.getHours()
const minutes = currentDate.getMinutes()
const seconds = currentDate.getSeconds()
const yearMonthDay = `${year}/${addCero(month + 1)}/${addCero(date)} ${addCero(hour)}:${addCero(minutes)}:${addCero(seconds)}`
return yearMonthDay
}
console.log(getDateNow())
module.exports = {
getDateNow
}