How to convert 2019-09-05T11:31:34.059Z this DateTime to offset 260.
database:mssql, datatype:datetimeoffset(7).
As one can identify current time-offset then how to convert the given date to this time-offset
You can also use the DateTimeOffset. LocalDateTime property to convert a DateTimeOffset value to a local DateTime value. The Kind property of the returned DateTime value is Local.
Changing Timezones of ZonedDateTime To convert a ZonedDateTime instance from one timezone to another, follow the two steps: Create ZonedDateTime in 1st timezone. You may already have it in your application. Convert the first ZonedDateTime in second timezone using withZoneSameInstant() method.
ConvertTime(DateTimeOffset, TimeZoneInfo) method that performs time zone conversions with ToOffset(TimeSpan) values. The method's parameters are a DateTimeOffset value and a reference to the time zone to which the time is to be converted. The method call returns a DateTimeOffset value.
In performing the conversion to local time, the method first converts the current DateTimeOffset object's date and time to Coordinated Universal Time (UTC) by subtracting the offset from the time. It then converts the UTC date and time to local time by adding the local time zone offset.
You can convert to prefered time zone by following way ,
new Date().toLocaleString("en-US", {timeZone: "America/New_York"})
<html>
<head>
<script language="JavaScript">
// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {
// create Date object for current location
d = new Date();
// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
nd = new Date(utc + (3600000*offset));
// return time as a string
return "The local time in " + city + " is " + nd.toLocaleString();
}
// get Bombay time
alert(calcTime('Bombay', '+5.5'));
// get Singapore time
alert(calcTime('Singapore', '+8'));
// get London time
alert(calcTime('London', '+1'));
</script>
</head>
<body>
</body>
</html>
If you are convenient with 3rd party libraries, you can go with moment.js along with moment-tz (moment with timezone).
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