Code Monkey home page Code Monkey logo

timezone's Introduction

timezone

Build Status

Requires Java 1.8.

Timezone Core

The timezone project can be imported into your project and run by directly interfacing with the public methods, without needing to start the web service. Add the project as a dependency and create a new TimeZones object, which can be interacted with through .getTimeZone() and .getOffsetDateTime() including all local time and timezone information such as current time in the timezone and offset from GMT.

Example:

TimeZones timeZones = new TimeZones();
timeZones.initWithWorldData(new File("./world-data/tz_world.shp").toURI().toURL());

TimeZone tz = timeZones.getTimeZone(40.713956,-75.767577);
long unixTimeStamp = 1488363179;
OffsetDateTime offsetDateTime = timeZones.getOffsetDateTime(unixTimeStamp,tz);
System.out.println(offsetDateTime);

//or even shorter
OffsetDateTime offsetDateTime2 = timeZones.getOffsetDateTime(unixTimeStamp,40.713956,-75.767577);
System.out.println(offsetDateTime2);

Timezone Webapp

Our timezone app turns your location and timestamp into timezone and local time. Thus, if you need local time in your application, just ask GraphHopper timezone. It is microservice you can run wherever you like.

Example

Example 1

request: http://localhost:8080/timezone?timestamp=1488363179&location=40.713956,-75.767577

response:

{

    "timezone": "America/New_York",
    "timezone_name": "Eastern Standard Time",
    "local_time": {
        "offset": -18000,
        "year": 2017,
        "month": "March",
        "day_of_month": 2,
        "day_of_week": "Thursday",
        "month_value": 3,
        "hour": 16,
        "minute": 19,
        "second": 52,
        "nano": 0
    }

}

Example 2

request: http://localhost:8080/timezone?timestamp=1488489592&location=48.873748,2.344482&language=fr

response:

{
    "timezone": "Europe/Paris",
    "timezone_name": "Heure d'Europe centrale",
    "local_time": {
        "offset": 3600,
        "year": 2017,
        "month": "mars",
        "day_of_month": 2,
        "day_of_week": "jeudi",
        "month_value": 3,
        "hour": 22,
        "minute": 19,
        "second": 52,
        "nano": 0
    }
}

Example 3

request: http://localhost:8080/timezone?timestamp=1488489592&location=36.031332,138.796876&language=ja

response:

{
    "timezone": "Asia/Tokyo",
    "timezone_name": "日本標準時",
    "local_time": {
        "offset": 32400,
        "year": 2017,
        "month": "3月",
        "day_of_month": 3,
        "day_of_week": "金曜日",
        "month_value": 3,
        "hour": 6,
        "minute": 19,
        "second": 52,
        "nano": 0
    }
}

try your own example:

Input & Output

You need to specify two parameters, (Unix) timestamp and location (lat,lon), and you will be provided with the according timezone, local time and offset to UTC. Local time and offset consider daylight saving time (dst).

Input:

Parameter Description
timestamp Unix timestamp (in seconds)
location latitude, longitude
language optional, default is 'en' - see the supported languages here

Output:

Name Description
timezone time zone id as defined here: http://efele.net/maps/tz/world/
timezone_name full name of time zone
local_time local time information considering daylight saving time

local_time:

Name Description
offset offset to UTC in seconds
year -
month -
day_of_month -
day_of_week -
month_value -
hour -
minute -
second -
nano -

TZ data

Make sure that you have updated your java environment with the latest tz data, otherwise old DST data might yield wrong local times. For example, such events "Russia Returns to Standard Time All Year" cause wrong local time calculations if you have not updated your JRE/JDK. You can update it as described here:

http://www.oracle.com/technetwork/java/javase/tzupdater-readme-136440.html

timezone's People

Contributors

afoeder avatar jguthrie100 avatar karussell avatar oblonski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.