Created
August 31, 2018 07:54
-
-
Save jastisriradheshyam/0a3ad908eb222a4e224e0ada13cff738 to your computer and use it in GitHub Desktop.
A Time Format function
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
// Gives the current Date Time in this format --> ddmmyyyy hh:mm:ss | |
var getLCurrentDateFormated = function () { | |
let date_now = new Date(); | |
return date_now.toLocaleString('en-IN', { day: "2-digit", month: "2-digit", year: "numeric", hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, timeZone: 'Asia/Kolkata' }).replace(/[\/\,]/g, ""); | |
} |
console.log(new Date("2018-10-11T12:00:00Z").toLocaleString('en-IN', {day:"2-digit", month:"short", year:"numeric"}))
Output
"11-Oct-2018"
console.log(new Date("2018-10-08T12:00:00Z").toLocaleString('en-IN', { day: "2-digit", month:"short", year:"numeric", hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, timeZone: 'Asia/Kolkata' }));
Output
"08-Oct-2018, 17:30:00"
new Date("2018-10-08T12:00:00Z").toLocaleString('sv-SE', { day:"2-digit" , month: "2-digit", year: "numeric", timeZone: 'Asia/Kolkata' })
Output
2018-10-08
function getISTInUTCDate(utcTime) {
let rawDate = new Date(utcTime);
let istDate = +rawDate.toLocaleString('en-US', {day:"2-digit", timeZone: 'Asia/Kolkata'});
let istMonth = +rawDate.toLocaleString('en-US', {month:"2-digit", timeZone: 'Asia/Kolkata'});
let istYear = +rawDate.toLocaleString('en-US', {year:"numeric", timeZone: 'Asia/Kolkata'});
let UTCSimilarDate = '';
return new Date(Date.UTC(istYear, istMonth-1, istDate, 0, 0, 0))
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
console.log(new Date("2018-10-08T12:00:00Z").toLocaleString('en-IN', { day:"2-digit" ,weekday: "long", month: "long", year: "numeric", hour: '2-digit', minute: '2-digit', hour12: true, timeZone: 'Asia/Kolkata' }));
Output