Skip to content

Instantly share code, notes, and snippets.

@acrispin
Created January 26, 2018 06:01
Show Gist options
  • Select an option

  • Save acrispin/a59e5ed31b98115f6f9948c599811c45 to your computer and use it in GitHub Desktop.

Select an option

Save acrispin/a59e5ed31b98115f6f9948c599811c45 to your computer and use it in GitHub Desktop.
Test Utc Java
/*
* 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