Created
January 26, 2018 06:01
-
-
Save acrispin/a59e5ed31b98115f6f9948c599811c45 to your computer and use it in GitHub Desktop.
Test Utc Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * To change this license header, choose License Headers in Project Properties. | |
| * To change this template file, choose Tools | Templates | |
| * and open the template in the editor. | |
| */ | |
| package com.console.test; | |
| import java.text.DecimalFormat; | |
| import java.util.TimeZone; | |
| /** | |
| * | |
| * @author Anton | |
| */ | |
| public class TestUtc { | |
| public static String getFormattedHour(int rawOffSet) { | |
| Double hours = rawOffSet / (3600*1000*1.0); | |
| int hour = hours.intValue(); | |
| long minutes = Math.abs(Math.round((hours-hour) * 60)); | |
| DecimalFormat df = new DecimalFormat("00"); | |
| return df.format(hour) + ":" + df.format(minutes); | |
| } | |
| public static void main(String[] args) { | |
| TimeZone timeZone = TimeZone.getDefault(); | |
| System.out.println("getDisplayName: " + timeZone.getDisplayName()); | |
| System.out.println("getID: " + timeZone.getID()); | |
| System.out.println("getRawOffset: " + timeZone.getRawOffset() / (3600*1000*1.0)); | |
| System.out.println("getRawOffset formatted: " + getFormattedHour(timeZone.getRawOffset())); | |
| System.out.println(""); | |
| TimeZone tz = TimeZone.getTimeZone("America/St_Johns"); | |
| System.out.println("getDisplayName2: " + tz.getDisplayName()); | |
| System.out.println("getID2: " + tz.getID()); | |
| System.out.println("getRawOffset2: " + tz.getRawOffset() / (3600*1000*1.0)); | |
| System.out.println("getRawOffset2 formatted: " + getFormattedHour(tz.getRawOffset())); | |
| System.out.println(""); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment