diff --git a/index.js b/index.js new file mode 100644 index 0000000..886312c --- /dev/null +++ b/index.js @@ -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 +} diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 9607059..3a62491 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1205,6 +1205,11 @@ "node": ">= 6" } }, + "node_modules/node-gmt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/node-gmt/-/node-gmt-0.0.2.tgz", + "integrity": "sha512-v8WiPWqVlG3+rMskh9EUu8Y4ZmxGIY7AG8z6rPXKWBXuv5FetHRzOmVyQRyW7x6FsZPtshFvzJjXI2aeDAaSJg==" + }, "node_modules/normalize-package-data": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", diff --git a/package-lock.json b/package-lock.json index 19150dc..f41d596 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "time-function", "version": "0.0.1", "license": "MIT", + "dependencies": { + "node-gmt": "^0.0.2" + }, "devDependencies": { "@commitlint/cli": "^15.0.0", "@commitlint/config-conventional": "^15.0.0", @@ -1215,6 +1218,11 @@ "node": ">= 6" } }, + "node_modules/node-gmt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/node-gmt/-/node-gmt-0.0.2.tgz", + "integrity": "sha512-v8WiPWqVlG3+rMskh9EUu8Y4ZmxGIY7AG8z6rPXKWBXuv5FetHRzOmVyQRyW7x6FsZPtshFvzJjXI2aeDAaSJg==" + }, "node_modules/normalize-package-data": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", @@ -2962,6 +2970,11 @@ "kind-of": "^6.0.3" } }, + "node-gmt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/node-gmt/-/node-gmt-0.0.2.tgz", + "integrity": "sha512-v8WiPWqVlG3+rMskh9EUu8Y4ZmxGIY7AG8z6rPXKWBXuv5FetHRzOmVyQRyW7x6FsZPtshFvzJjXI2aeDAaSJg==" + }, "normalize-package-data": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", diff --git a/package.json b/package.json index 96f1cf8..fc9b695 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,8 @@ "@commitlint/cli": "^15.0.0", "@commitlint/config-conventional": "^15.0.0", "husky": "^4.3.8" + }, + "dependencies": { + "node-gmt": "^0.0.2" } }