List of usage examples for java.util Calendar set
public final void set(int year, int month, int date)
YEAR
, MONTH
, and DAY_OF_MONTH
. From source file:MainClass.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.set(2001, 1, 1); }
From source file:Main.java
public static void main(String[] args) { Calendar first = Calendar.getInstance(); first.set(2008, Calendar.AUGUST, 1); Calendar second = Calendar.getInstance(); System.out.println(getDifference(first, second, TimeUnit.DAYS) + " day(s) between "); }
From source file:Main.java
public static void main(String args[]) { int days = 1; int month = 1; int year = 2001; SimpleDateFormat sdf = new SimpleDateFormat("E dd-MM-yyyy G"); StringBuffer buf = new StringBuffer(); Calendar cal = new GregorianCalendar(); cal.set(year, month - 1, days); sdf.format(cal.getTime(), buf, new FieldPosition(10)); System.out.println(buf.toString()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal1 = Calendar.getInstance(); cal1.set(2015, 2, 27); Calendar cal2 = Calendar.getInstance(); cal2.set(2015, 8, 1);/*from w w w. j a v a 2 s .co m*/ boolean valid = isSixMonthsAgo(cal1, cal2); System.out.println(valid); }
From source file:Main.java
/** Typical main method ("main program") declaration */ public static void main(String[] av) { Locale l1 = new Locale("en", "US"), l2 = new Locale("es", "ES"); // Create a Date object for May 5, 1986 Calendar c = Calendar.getInstance(); c.set(1986, 04, 05); // May 5, 1986 Date d1 = c.getTime();/*from w ww . j av a 2 s.co m*/ // Create a Date object for today. Date d2 = new Date(); // today DateFormat df_us = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l1), df_sp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l2); System.out.println("Date d1 for US is " + df_us.format(d1)); System.out.println("Date d1 for Spain is " + df_sp.format(d1)); System.out.println("Date d2 is " + df_us.format(d2)); }
From source file:Main.java
public static void main(String[] args) { Calendar startEmployment = Calendar.getInstance(); startEmployment.set(2010, 2, 1); startEmployment.set(2011, Calendar.FEBRUARY, 1); Calendar now = Calendar.getInstance(); long numberOfDays1 = countDays(startEmployment, now); System.out.println(numberOfDays1); }
From source file:Main.java
public static void main(String args[]) { Calendar cal1 = new GregorianCalendar(); Calendar cal2 = new GregorianCalendar(); cal1.set(2010, 12, 1); cal2.set(2011, 9, 31);/*ww w. j a v a2 s .c om*/ System.out.println("Days= " + daysBetween(cal1.getTime(), cal2.getTime())); }
From source file:org.lieuofs.extraction.commune.mutation.ExtracteurMutation.java
public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "beans_extraction.xml" }); ExtracteurMutation extracteur = (ExtracteurMutation) context.getBean("extracteurMutation"); Calendar cal = Calendar.getInstance(); cal.set(2013, Calendar.JANUARY, 1); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("MutationCommune2013.txt"), "Windows-1252")); extracteur.extraireMutation(cal.getTime(), writer); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.set(2015, 01, 10); calendar2.set(2015, 07, 01);//from w ww . j a v a2 s. c o m long milliseconds1 = calendar1.getTimeInMillis(); long milliseconds2 = calendar2.getTimeInMillis(); long diff = milliseconds2 - milliseconds1; long diffSeconds = diff / 1000; long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000); System.out.println("\nThe Date Different Example"); System.out.println("Time in milliseconds: " + diff + " milliseconds."); System.out.println("Time in seconds: " + diffSeconds + " seconds."); System.out.println("Time in minutes: " + diffMinutes + " minutes."); System.out.println("Time in hours: " + diffHours + " hours."); System.out.println("Time in days: " + diffDays + " days."); }
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); // print the result System.out.println("Altered year is :" + cal.getTime()); }