getting time zone when entering state and country (time zone to use in ics file)

后端 未结 3 1689
南笙
南笙 2021-01-22 00:31

Getting time zone when giving state and country in text box

is there any way to get the time zone of that place with this two values?

the input

3条回答
  •  梦毁少年i
    2021-01-22 01:24

    No, there is no pre-defined methods exists.

    For this you need some external web services. If you're interested you can create your own API using the information provided here in wikipedia

    Updates: Based on your comments "get local time zone of the current browser

    var date = new Date(); 
    

    returns 12:38:05 GMT+0530 (India Standard Time)

    To pick the time within the bracket use

    date.toTimeString().match(/\(([^)]+)\)/)[1];
    

    returns India Standard Time

    Check this JSFiddle

    But this is not you expected, however you should try Auto detect a time zone with JavaScript and for updated version try this jsTimezoneDetect

提交回复
热议问题