Skip to content

Instantly share code, notes, and snippets.

@jastisriradheshyam
Created August 31, 2018 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jastisriradheshyam/0a3ad908eb222a4e224e0ada13cff738 to your computer and use it in GitHub Desktop.
Save jastisriradheshyam/0a3ad908eb222a4e224e0ada13cff738 to your computer and use it in GitHub Desktop.
A Time Format function
// 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, "");
}
@jastisriradheshyam
Copy link
Author

jastisriradheshyam commented Oct 9, 2018

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

"Monday, 08 October, 2018, 5:30 PM"

@jastisriradheshyam
Copy link
Author

console.log(new Date("2018-10-11T12:00:00Z").toLocaleString('en-IN', {day:"2-digit", month:"short", year:"numeric"}))

Output

"11-Oct-2018"

@jastisriradheshyam
Copy link
Author

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"

@jastisriradheshyam
Copy link
Author

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

@jastisriradheshyam
Copy link
Author

jastisriradheshyam commented Jan 31, 2019

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