List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.set(Calendar.HOUR_OF_DAY, 10); // 0..23 japanCal.set(Calendar.MINUTE, 0); japanCal.set(Calendar.SECOND, 0); Calendar local = new GregorianCalendar(); local.setTimeInMillis(japanCal.getTimeInMillis()); }
From source file:Main.java
public static void main(String[] args) { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); long now = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(now); System.out.println(now + " = " + formatter.format(calendar.getTime())); }
From source file:Main.java
public static void main(String[] args) { Calendar today = new GregorianCalendar(); Calendar purchased = new GregorianCalendar(); purchased.add(Calendar.DAY_OF_MONTH, 1); Calendar lastActDate = new GregorianCalendar(); lastActDate.setTimeInMillis(today.getTimeInMillis() - purchased.getTimeInMillis()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.set(Calendar.HOUR_OF_DAY, 10); // 0..23 japanCal.set(Calendar.MINUTE, 0); japanCal.set(Calendar.SECOND, 0); Calendar local = new GregorianCalendar(); local.setTimeInMillis(japanCal.getTimeInMillis()); int hour = local.get(Calendar.HOUR); // 5 int minutes = local.get(Calendar.MINUTE); // 0 int seconds = local.get(Calendar.SECOND); // 0 boolean am = local.get(Calendar.AM_PM) == Calendar.AM; // false }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar local = Calendar.getInstance(); Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.setTimeInMillis(local.getTimeInMillis()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar local = Calendar.getInstance(); Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.setTimeInMillis(local.getTimeInMillis()); int hour = japanCal.get(Calendar.HOUR); // 3 int minutes = japanCal.get(Calendar.MINUTE); // 0 int seconds = japanCal.get(Calendar.SECOND); // 0 boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; // true }
From source file:Main.java
public static void main(String[] args) { Calendar localTime = Calendar.getInstance(); localTime.set(Calendar.HOUR, 17); localTime.set(Calendar.MINUTE, 15); localTime.set(Calendar.SECOND, 20); int hour = localTime.get(Calendar.HOUR); int minute = localTime.get(Calendar.MINUTE); int second = localTime.get(Calendar.SECOND); System.out.printf("Local time : %02d:%02d:%02d\n", hour, minute, second); Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany")); germanyTime.setTimeInMillis(localTime.getTimeInMillis()); hour = germanyTime.get(Calendar.HOUR); minute = germanyTime.get(Calendar.MINUTE); second = germanyTime.get(Calendar.SECOND); System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second); }
From source file:EventObject.java
public static void main(String[] args) { JFrame f = new JFrame(); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(event.getWhen()); Locale locale = Locale.getDefault(); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date()); if (event.getID() == ActionEvent.ACTION_PERFORMED) System.out.println(" Event Id: ACTION_PERFORMED"); System.out.println(" Time: " + s); String source = event.getSource().getClass().getName(); System.out.println(" Source: " + source); int mod = event.getModifiers(); if ((mod & ActionEvent.ALT_MASK) > 0) System.out.println("Alt "); if ((mod & ActionEvent.SHIFT_MASK) > 0) System.out.println("Shift "); if ((mod & ActionEvent.META_MASK) > 0) System.out.println("Meta "); if ((mod & ActionEvent.CTRL_MASK) > 0) System.out.println("Ctrl "); }/*w w w.j a va 2 s .c o m*/ }); f.add(ok); f.setSize(420, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:com.mozilla.bagheera.util.IdUtil.java
public static void main(String[] args) throws IOException { String id = "06b87727-2946-4b1e-b654-8bafb60bb995"; long timestamp = 1360493115891L; Calendar cal = Calendar.getInstance(); //cal.set(2013, Calendar.FEBRUARY, 10); cal.setTimeInMillis(timestamp); System.out.println(IdUtil.hbaseShellId(id, cal.getTime())); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the time in milliseconds System.out.println("Current time is :" + cal.getTime()); // set time to 5000000000 ms after january 1 1970 cal.setTimeInMillis(5000000000L); // print the new time System.out.println("After setting Time: " + cal.getTime()); }