bnjunge / Daraja-Node-Js-Tutorial

This a repo for Tutorials on Daraja << Node Js >>
24 stars 16 forks source link

The getMonth() in timestamp gives the previous month #1

Closed markarik closed 3 years ago

wheezyy commented 4 years ago

Use this function

https://medium.com/@nmdaniel/fullstack-lipanampesa-api-web-app-with-nodejs-mongodb-atlas-d0c263e56862

function getTimeStamp() { function parseDate(e) { return e < 10 ? "0" + e : e; } var _date = new Date(); var currentTime = new Date( _date.toLocaleString("en-us", { timeZone: "Africa/Nairobi" }) ); var month = parseDate(currentTime.getMonth() + 1); var date = parseDate(currentTime.getDate()); var hour = parseDate(currentTime.getHours()); var minutes = parseDate(currentTime.getMinutes()); var seconds = parseDate(currentTime.getSeconds()); return ( currentTime.getFullYear() + "" + month + "" + date + "" + hour + "" + minutes + "" + seconds ); }

bnjunge commented 3 years ago

Use Moment js to format the date.