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.
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);
use toLocaleString
and provide desired timezone:
new Date("yourInputDateInASuitableFormat").toLocaleString("en-US", {timeZone: 'Asia/Kolkata'})
const getISTTime = () => {
let d = new Date()
return d.getTime() + ( 5.5 * 60 * 60 * 1000 )
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With