List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static String getClockTimeFromSeconds(long secs) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(secs * 1000L);/*w w w.ja va2 s .com*/ return String.format("%02d:%02d", c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); }
From source file:Main.java
/** * Determines what year a transaction belongs to. * //from w ww .ja v a 2s .c o m * If the given <code>day</code> of the given <code>month</code> for the current year * is in the future the transaction is probably from last year. * * @param month The month, where January is 1. * @param day The day of the month, starting from 1. * @return An ISO 8601 formatted date. */ public static String getTransactionDate(int month, int day) { month--; // Java-months start at 0 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); int currentYear = cal.get(Calendar.YEAR); cal.set(currentYear, month, day, 0, 0); if (cal.getTime().after(Calendar.getInstance().getTime())) { //If the transaction is in the future the year is probably of by +1. cal.add(Calendar.YEAR, -1); } return sdf.format(cal.getTime()); }
From source file:Main.java
public static int getWeekOfDate() { Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTime(new Date()); int k = calendar.get(Calendar.DAY_OF_WEEK) - 1; if (k < 1) k = 7;/* www.j av a 2 s .c o m*/ return k; }
From source file:Main.java
public static String getTimeStampDDMMYYYY(long l) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(l);/*from w w w . j ava 2 s . c om*/ return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4); }
From source file:Main.java
private static Date getDateBefore() { Date nowtime = new Date(); Calendar now = Calendar.getInstance(); now.setTime(nowtime);/* ww w . j a v a2 s . com*/ now.set(Calendar.DATE, now.get(Calendar.DATE) - LOG_SAVE_DAYS); return now.getTime(); }
From source file:Main.java
public static boolean isSameDateInCalendar(Calendar calendar, Date date) { Calendar dateCalendar = Calendar.getInstance(); dateCalendar.setTime(date);/*w ww . jav a2 s.c o m*/ return dateCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH) && dateCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH) && dateCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR); }
From source file:Main.java
public static int getDayOfWeek() { return Calendar.getInstance().get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static int getCurYear() { return Calendar.getInstance().get(Calendar.YEAR); }
From source file:com.googlecode.commons.swing.util.DateUtils2.java
public static int getWeekNumber(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d);/*w w w. j ava 2 s. c om*/ return cal.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static int getDayOfWeek(Date date, int defSunday) { Calendar c = Calendar.getInstance(); c.setTime(date);/*from w w w. j a v a 2 s. c om*/ int day = c.get(Calendar.DAY_OF_WEEK); switch (day) { case Calendar.MONDAY: return 1; case Calendar.TUESDAY: return 2; case Calendar.WEDNESDAY: return 3; case Calendar.THURSDAY: return 4; case Calendar.FRIDAY: return 5; case Calendar.SATURDAY: return 6; case Calendar.SUNDAY: return defSunday; default: return 0; } }