List of usage examples for java.util Calendar get
public int get(int field)
From source file:com.glaf.core.job.SysDataLogCreateTableJob.java
public static void main(String[] args) { Date date = DateUtils.getDateAfter(new Date(), 0); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w. j a v a2 s .c o m int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int daysOfMonth = DateUtils.getYearMonthDays(year, month + 1); calendar.set(year, month, daysOfMonth); int begin = getYearMonthDay(date); int end = getYearMonthDay(calendar.getTime()); for (int i = begin; i <= end; i++) { logger.debug(i); try { SysDataLogTableUtils.createTable("SYS_DATA_LOG_" + i); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Calendar future = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); future.set(Calendar.YEAR, 2015); System.out.println("Year is " + future.get(Calendar.YEAR)); Date time = future.getTime(); if (future.after(cal)) { System.out.println("Date " + time + " is after current date."); }// w w w. j a v a 2s . c om }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); // add seconds to current date now.add(Calendar.SECOND, 500); System.out.println("adding 500 seconds : "); System.out.println(now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); // adding minus value now = Calendar.getInstance(); now.add(Calendar.SECOND, -500); System.out.println("adding -500 seconds: "); System.out.println(now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); }
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:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2007); cal.set(Calendar.DAY_OF_YEAR, 180); System.out.println("Calendar date is: " + cal.getTime()); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Calendar day of month: " + dayOfMonth); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); System.out.println("Calendar day of week: " + dayOfWeek); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); String[] strDays = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thusday", "Friday", "Saturday" }; System.out.println("Current day is : " + strDays[now.get(Calendar.DAY_OF_WEEK) - 1]); }
From source file:camera.Camera.java
/** * @param args the command line arguments *//*from w ww. j a v a 2 s. com*/ public static void main(String[] args) throws Exception { System.out.println("start compass."); // Compass c = new Compass(); // c.start(); System.out.println("start camera."); Camera cam = new Camera(); cam.snapshot(); // regelmssig zu festen Sekunden Foto schiessen. Thread. int phase; int lastPhase = -1; while (true) { Calendar cal = new GregorianCalendar(); int stunde = cal.get(Calendar.HOUR_OF_DAY); int STUNDE_VON = 7; int STUNDE_BIS = 23; if ((stunde < STUNDE_VON) || (stunde > STUNDE_BIS)) { Thread.sleep(1000); continue; } // regelmssig Fotos int sekunde = cal.get(Calendar.SECOND); phase = sekunde / 10; // alle 10 sekunden wechsel jede volle zehner wechselt //phase = phase % 4; // 4 phasen wenn ma unterteilen wollte if (phase == lastPhase) { // Thread.sleep(300); // continue; } lastPhase = phase; // zeit fr ein Foto. cam.snapshot(); } }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Calendar past = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); // change year in past calendar past.set(Calendar.YEAR, 2013); System.out.println("Year is " + past.get(Calendar.YEAR)); // check if calendar date is before current date System.out.println(cal.before(past)); }
From source file:Test.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); if (calendar.isWeekDateSupported()) { System.out.println("Number of weeks in this year: " + calendar.getWeeksInWeekYear()); System.out.println("Current week number: " + calendar.get(Calendar.WEEK_OF_YEAR)); }/*from w w w .ja va 2 s. co m*/ calendar.setWeekDate(2012, 16, 3); System.out.println( DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime())); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_MONTH, 1); // day of week for first date of month int weekOfFirstDate = calendar.get(Calendar.WEEK_OF_YEAR); int lastDateOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_MONTH, lastDateOfMonth); // day of week for last date of month int weekOfLastDate = calendar.get(Calendar.WEEK_OF_YEAR); calendar.roll(Calendar.MONTH, false); int lastDateOfPrevMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); int weeksToDisplay = weekOfLastDate - weekOfFirstDate + 1; int[] days = new int[weeksToDisplay * 7]; int firstDayPosition = 3; // fill previous month int x = lastDateOfPrevMonth; for (int i = firstDayPosition - 1; i >= 0; i--) { days[i] = x--;// w w w.ja v a 2 s . c o m } // fill current month for (int i = 1; i < lastDateOfMonth + 1; i++) { days[firstDayPosition - 1 + i] = i; } // fill next month int j = 1; for (int i = lastDateOfMonth + firstDayPosition; i < days.length; i++) { days[i] = j++; } for (int i = 0; i < days.length; i++) { if (i % 7 == 0) { System.out.println(); } System.out.print(days[i] + "\t"); } }