How to get device's timezone with expo-localization? - javascript

expo-localization's documentations says this about the Localization.timezone:
Deprecated. Use Localization.getLocales() instead.
But the Localization.getLocales() returns a Locale object, which has the following attributes, none of which is timezone or anything that could help find it:
So how would I get a user's timezone with this package?

You may try this one
Intl.DateTimeFormat().resolvedOptions().timeZone
It is alternatively return the same thing as you are expected

Related

How to get moment-timezone current configured timezone?

So when we configure a default timezone using moment-timezone we do something like this:
moment.tz.setDefault('America/Sao_Paulo')
I was looking for a way to retrieve that value (America/Sao_Paulo) from the moment.tz object... I wasn't able to find it on their documentation page :/ I was assuming it would be something similar to moment.tz.getCurrent() // America/Sao_Paulo
Btw, this is not the same as moment.tz.guess(), because I don't want the user's local timezone, I want literally what is the timezone configured currently on moment, regardless of the browser's timezone.
I'm also in a similar boat. There appears to be an undocumented attribute on moment that is set after you guess the timezone.
moment.defaultZone
Haven't found how it can be used with other moment-timezone methods yet.

momentjs deprecated warning not going away

somestringvar = moment(entry.expirationDate, "MM/DD/YYYY").format("MMM-DD-YYYY").toString();
The date is correctly converted to the format I need like Nov-11-2018 but I just cannot get rid of that infamous moment js deprecated warning. Tried many combinations. The warning I get is
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers
Please advise how to get rid of this warning. I am using latest angular version and typescript code. Thanks
A simple way to get around is changing the moment constructor to moment(new Date(entry.expirationDate)).

moment locale not set correctly

We're trying to find a problem with tests that use moment.js and fail when run on a server in Arizona but succeed when run locally here in the UK. We manually set the locale before creating a moment and can see that the local 'en-gb' is installed.
This fiddle highlights what I think the problem is (Need to set computer to Arizona Time zone first!) https://jsfiddle.net/2ve10ax4/
moment.locale('en-gb');
console.log(moment.locale());
// en-gb
console.log(moment('2016-05-01T00:00:00+00:00').format());
// 2016-04-30T17:00:00-07:00
I'm expecting to see the date formatted with respect to 'en-gb' locale but it shows it with respect to Arizona time. Am I missing something?
Locale and timezone are orthogonal things. A locale does not specify a timezone unambigously. You need to set your timezone separately. You can use Momemt Timezone, and then you can use e.g.
.tz('Europe/London')
By setting moment.locale('en-gb') you have specified a locale/language (brittish-english), not a timezone.
To specify a timezone you need to include the Moment.js Timezone library in your project, and then do something like:
console.log(moment('2016-05-01T00:00:00+00:00').tz('America/Phoenix').format());
The above will give you the timezone for Arizona.
After reading more I believe parseZone is the correct solution, given that I am already including Time Zone information in the date string.
console.log(moment.parseZone('2016-05-01T00:00:00+00:00').format());

JavaScript : Convert TimeZone Offset to TimeZone String (Eg: "-5.00" to "CST")

I am getting a timezone offset as "-5.00" from a service response and I need to format it in the UI as CST. How do I convert this in JavaScript? I searched and am not sure there is any direct method in JavaScript.
I would look at using Moment. It provides a full timezone library. You may be able to make use of it still depending on your requirements and situation.
http://momentjs.com/timezone/

using moment js to pass in time zone and get hours offset?

I want to pass a three-digit time zone string like "GMT" or "EST" and get the offset like "-05:00" as a string from it.
Moment seems to handle it but I couldn't find a way...
This capability you are asking about has been deprecated. Tim Wood in this thread says:
The problem is that Date.prototype.toString returns such different results. That is the only place to get the timezone name (PST, CST, EST, etc). If this method is not returning any timezone information (as is the case with FF10 and IE9, there is no way to get it.
In that same thread there are mentions by some people about how they are able to get the abbreviated time zone and consequently pass it to moment but only in certain browsers.

Categories

Resources