List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:Main.java
public static void main(String[] args) { Calendar calTokyo = Calendar.getInstance(); calTokyo.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo")); System.out.println(/*from w w w .ja v a 2 s .c om*/ "Time in Tokyo: " + calTokyo.get(Calendar.HOUR_OF_DAY) + ":" + calTokyo.get(Calendar.MINUTE)); }
From source file:Main.java
public static void main(String[] args) { Calendar calParis = Calendar.getInstance(); calParis.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); System.out.println(/*from w w w. j a v a 2s. co m*/ "Time in Paris: " + calParis.get(Calendar.HOUR_OF_DAY) + ":" + calParis.get(Calendar.MINUTE)); }
From source file:Main.java
public static void main(String[] args) { Calendar calNewYork = Calendar.getInstance(); calNewYork.setTimeZone(TimeZone.getTimeZone("America/New_York")); System.out.println("Time in New York: " + calNewYork.get(Calendar.HOUR_OF_DAY) + ":" + calNewYork.get(Calendar.MINUTE)); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myDate DATE );"); String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime()); pstmt.setDate(2, sqlDate);//from w w w .j ava2 s. c o m pstmt.executeUpdate(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); Calendar cal = Calendar.getInstance(); // get the TimeZone for "America/Los_Angeles" TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); cal.setTimeZone(tz); while (rs.next()) { // the JDBC driver will use the time zone information in // Calendar to calculate the date, with the result that // the variable dateCreated contains a java.sql.Date object // that is accurate for "America/Los_Angeles". java.sql.Date dateCreated = rs.getDate(2, cal); System.out.println(dateCreated); } rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println(cal.getTimeZone().getDisplayName()); TimeZone tz = TimeZone.getTimeZone("GMT"); // set the time zone with the given time zone value and print it cal.setTimeZone(tz); System.out.println(cal.getTimeZone().getDisplayName()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Get the current time in Hong Kong Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong")); int hour12 = cal.get(Calendar.HOUR); // 0..11 int minutes = cal.get(Calendar.MINUTE); // 0..59 int seconds = cal.get(Calendar.SECOND); // 0..59 boolean am = cal.get(Calendar.AM_PM) == Calendar.AM; // Get the current hour-of-day at GMT cal.setTimeZone(TimeZone.getTimeZone("GMT")); int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 // Get the current local hour-of-day cal.setTimeZone(TimeZone.getDefault()); hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 }
From source file:org.gogpsproject.parser.rinex.RinexNavigation.java
/** * @param args/*from ww w . ja v a2 s . c om*/ */ public static void main(String[] args) { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 2011); c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 9); c.set(Calendar.HOUR_OF_DAY, 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.setTimeZone(new SimpleTimeZone(0, "")); Time t = new Time(c.getTimeInMillis()); System.out.println("ts: " + t.getMsec() + " " + (new Date(t.getMsec()))); System.out.println("week: " + t.getGpsWeek()); System.out.println("week sec: " + t.getGpsWeekSec()); System.out.println("week day: " + t.getGpsWeekDay()); System.out.println("week hour in day: " + t.getGpsHourInDay()); System.out.println("ts2: " + (new Time(t.getGpsWeek(), t.getGpsWeekSec())).getMsec()); RinexNavigation rn = new RinexNavigation(IGN_NAVIGATION_HOURLY_ZIM2); rn.init(); // SatellitePosition sp = rn.getGpsSatPosition(c.getTimeInMillis(), 2, 0, 0); Observations obs = new Observations(new Time(c.getTimeInMillis()), 0); SatellitePosition sp = rn.getGpsSatPosition(obs, 2, 'G', 0); if (sp != null) { System.out .println("found " + (new Date(sp.getUtcTime())) + " " + (sp.isPredicted() ? " predicted" : "")); } else { System.out.println("Epoch not found " + (new Date(c.getTimeInMillis()))); } }
From source file:org.gogpsproject.parser.sp3.SP3Navigation.java
/** * @param args//from w w w .jav a 2 s .c o m */ public static void main(String[] args) { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Calendar c = Calendar.getInstance(); // c.set(Calendar.YEAR, 2011); // c.set(Calendar.MONTH, 0); // c.set(Calendar.DAY_OF_MONTH, 9); // c.set(Calendar.HOUR_OF_DAY, 1); // c.set(Calendar.MINUTE, 0); // c.set(Calendar.SECOND, 0); // c.set(Calendar.MILLISECOND, 0); c.setTimeZone(new SimpleTimeZone(0, "")); Time t = new Time(c.getTimeInMillis()); System.out.println("ts: " + t.getMsec() + " " + (new Date(t.getMsec()))); System.out.println("week: " + t.getGpsWeek()); System.out.println("week sec: " + t.getGpsWeekSec()); System.out.println("week day: " + t.getGpsWeekDay()); System.out.println("week hour in day: " + t.getGpsHourInDay()); System.out.println("year: " + t.getYear() + " " + t.getYear2c()); System.out.println("day of year: " + t.getDayOfYear()); System.out.println("ts2: " + (new Time(t.getGpsWeek(), t.getGpsWeekSec())).getMsec()); // SP3Navigation sp3n = new SP3Navigation(IGN_FR_ULTRARAPID); // sp3n.init(); // SatellitePosition sp = sp3n.getGpsSatPosition(c.getTimeInMillis(), 2, 0, null); // if(sp!=null){ // System.out.println("found "+(new Date(sp.getUtcTime()))+" "+(sp.isPredicted()?" predicted":"")); // }else{ // System.out.println("Epoch not found "+(new Date(c.getTimeInMillis()))); // } }
From source file:Main.java
public static long getUTCTime() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("gmt")); return cal.getTimeInMillis(); }
From source file:Main.java
public static boolean gpwActive() { Calendar c = Calendar.getInstance(); c.setTimeZone(WARSAW_TIMEZONE); return !isWeekend(c) && workingHours(c); }