List of usage examples for java.util Calendar set
public final void set(int year, int month, int date, int hourOfDay, int minute, int second)
YEAR
, MONTH
, DAY_OF_MONTH
, HOUR_OF_DAY
, MINUTE
, and SECOND
. From source file:MainClass.java
public static void main(String[] pArgs) throws Exception { Calendar cal = Calendar.getInstance(); cal.set(2004, 2, 5, 10, 2, 2); System.out.println(DateUtils.round(cal.getTime(), DateUtils.SEMI_MONTH)); }
From source file:Main.java
public static void main(String[] args) throws Exception { Calendar start = Calendar.getInstance(); start.set(2015, 1, 21, 11, 1, 11); Calendar end = Calendar.getInstance(); Calendar clone = (Calendar) start.clone(); int year = elapsed(clone, end, Calendar.YEAR); System.out.println(year + " year"); clone.add(Calendar.YEAR, year); int month = elapsed(clone, end, Calendar.MONTH); clone.add(Calendar.MONTH, month); System.out.println(month + " month"); int date = elapsed(clone, end, Calendar.DATE); clone.add(Calendar.DATE, date); System.out.println(date + " day"); int hour = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 3600000; clone.add(Calendar.HOUR, hour); System.out.println(hour + " hour"); int minute = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 60000; clone.add(Calendar.MINUTE, minute); System.out.println(minute + " minute"); int millis = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 1000; System.out.println(millis + " millis"); }
From source file:Main.java
public static void main(String args[]) { Calendar c1 = new GregorianCalendar(); Calendar c2 = new GregorianCalendar(); c1.set(2000, 12, 12, 0, 0, 0); c2.set(2001, 12, 12, 0, 0, 0);//from www.ja v a 2 s.co m System.out.println(daysBetween(c1.getTime(), c2.getTime()) + " day(s) between " + args[0] + "-" + args[1] + "-" + args[2] + " and " + args[3] + "-" + args[4] + "-" + args[5]); }
From source file:CalCalcs.java
public static void main(String[] argv) { //+//w w w .ja v a2 s. c o m Calendar c = Calendar.getInstance(); System.out.println("I got a " + c.getClass()); c.set(1951, 03, 24, 12, 30, 0); System.out.println("I set it to " + c.getTime().toString()); System.out.println("I actually set the year to " + c.get(Calendar.YEAR)); System.out.println("In milliseconds, that's " + c.getTime().getTime()); System.out.println("Or, in seconds, " + c.getTime().getTime() / 1000); //- }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // print current time System.out.println("Current year is :" + cal.getTime()); // set the year,month and day to something else cal.set(2013, 5, 25, 04, 15, 20); System.out.println("Altered year is :" + cal.getTime()); }
From source file:Main.java
public static long getTimesMonthStart() { Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); return cal.getTimeInMillis(); }
From source file:Main.java
public static long getTimesMonthMorning() { Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); return cal.getTimeInMillis(); }
From source file:Main.java
public static Date dateWithYear(int year, int month, int day, int h, int m, int s) { Calendar cal = Calendar.getInstance(); cal.set(year, month, day, h, m, s); return cal.getTime(); }
From source file:Main.java
public static long getTimesMonthNextStart() { Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, 24); return cal.getTimeInMillis(); }
From source file:Main.java
public static long timeToMills(String timeString) { Calendar c = Calendar.getInstance(); c.set(Integer.parseInt(timeString.substring(0, 4)), Integer.parseInt(timeString.substring(4, 6)) - 1, Integer.parseInt(timeString.substring(6, 8)), Integer.parseInt(timeString.substring(8, 10)), Integer.parseInt(timeString.substring(10, 12)), Integer.parseInt(timeString.substring(12, 14))); return c.getTimeInMillis(); }