Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get IST time in javascript

<script type="text/javascript">
<!--
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

if (minutes < 10)
minutes = "0" + minutes

document.write("<b>" + hours + ":" + minutes + " " + "</b>")
//-->
</script>

Getting local comupter time. I want to get IST time in javascript.

like image 983
user3371310 Avatar asked Mar 02 '14 22:03

user3371310


People also ask

How to get indian standard time in JavaScript?

var currentDa = new Date(); var nowTime = new Date(currentDa. getTime()); var Chour = nowTime. getHours(); var Cminute = nowTime. getMinutes(); var currentTime = (+Chour + "." + Cminute);

How to get current EST Date in JavaScript?

JS get current time in ESTconst date = new Date(); var offset = -300; //Timezone offset for EST in minutes.

How do I get rid of Z in time?

To remove the T and Z characters from an ISO date in JavaScript, we first need to have the date in ISO format. If you don't have it already, you can convert it to ISO using the toISOString function on a Date object. This will get rid of both T and Z, resulting in "2022-06-22 07:54:52.657".


1 Answers

The following will allow you to convert local time to IST time:

var currentTime = new Date();

var currentOffset = currentTime.getTimezoneOffset();

var ISTOffset = 330;   // IST offset UTC +5:30 

var ISTTime = new Date(currentTime.getTime() + (ISTOffset + currentOffset)*60000);

// ISTTime now represents the time in IST coordinates

var hoursIST = ISTTime.getHours()
var minutesIST = ISTTime.getMinutes()

document.write("<b>" + hoursIST + ":" + minutesIST + " " + "</b>")
like image 150
Mike Dinescu Avatar answered Oct 04 '22 14:10

Mike Dinescu