Skip to content

Instantly share code, notes, and snippets.

@jastisriradheshyam
Created August 31, 2018 07:54
Show Gist options
  • 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 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