Home how to convert facebook's userinfo timzone field to Time Zone name?
Reply: 1

how to convert facebook's userinfo timzone field to Time Zone name?

vimal prakash
1#
vimal prakash Published in 2018-02-12 07:51:42Z

This question already has an answer here:

  • Parse timezone int to string (timezone name) (facebook api) 2 answers

I am getting user info from facebook after using oauth2 access_token

{
 ...
 "timezone": 5.5,
}

now I need to convert this to Zone Name to fill the openid connect zoneinfo filed.

ex : "Asia/Calcutta"

I am requesting from India , in timezone map I am seeing +05:30 is correct one. but facebook is issuing 5.5 I am not able solve this issue. please help me on this.

Ole V.V.
2#
Ole V.V. Reply to 2018-02-13 12:50:27Z

I still don’t know which language you’re after (if any particular). Here’s a Java solution:

    long secondsPerHour = TimeUnit.HOURS.toSeconds(1);
    long offsetSeconds = Math.round(5.5 * secondsPerHour);
    if (offsetSeconds < ZoneOffset.MIN.getTotalSeconds()
            || offsetSeconds > ZoneOffset.MAX.getTotalSeconds()) {
        System.out.println("Not a valid UTC offset, is out of range");
    } else {
        ZoneOffset offset = ZoneOffset.ofTotalSeconds((int) offsetSeconds);
        System.out.println(offset);
    }

It prints

+05:30

You can use the ZoneOffset from this snippet anywhere a ZoneId is expected, since ZoneOffset is a subclass of ZoneId. ZoneId is the modern Java class to represent a time zone.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.334767 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO