Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert the time stamp UTC to IST using JavaScript

Tags:

javascript

I'm looking for a suitable way to convert a timestamp from UTC to IST using JavaScript DateTimeStamp "20160108120040".

The timestamp comes from an XML in my body request.

like image 253
Pramod SR Avatar asked Apr 07 '16 18:04

Pramod SR


3 Answers

First thing, take a look at JavaScript date formats and convert your input date accordingly, then you shoud take a look to the methods available in JavaScript for date manipulation (no external library required). It's pretty easy to do something like this:

var dateUTC = new Date("yourInputDateInASuitableFormat");
var dateUTC = dateUTC.getTime() 
var dateIST = new Date(dateUTC);
//date shifting for IST timezone (+5 hours and 30 minutes)
dateIST.setHours(dateIST.getHours() + 5); 
dateIST.setMinutes(dateIST.getMinutes() + 30);
like image 124
Matteo Baldi Avatar answered Oct 08 '22 23:10

Matteo Baldi


use toLocaleString and provide desired timezone:

new Date("yourInputDateInASuitableFormat").toLocaleString("en-US", {timeZone: 'Asia/Kolkata'})
like image 4
GorvGoyl Avatar answered Oct 08 '22 23:10

GorvGoyl


const getISTTime = () => {
  let d = new Date()
  return d.getTime() + ( 5.5 * 60 * 60 * 1000 )
}
like image 3
Pravas Avatar answered Oct 08 '22 23:10

Pravas