List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static String getTodayDateString() { Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH) + 1; int day = now.get(Calendar.DAY_OF_MONTH); String monthStr = String.valueOf(month); String dayStr = String.valueOf(day); if (month < 10) { monthStr = "0" + dayStr; }/* ww w .j ava 2 s. c om*/ if (day < 10) { dayStr = "0" + dayStr; } String nowDate = year + "-" + monthStr + "-" + dayStr; return nowDate; }
From source file:Main.java
public static String getSubscribeTime(long time) { try {//from w w w.j ava 2s. c om SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String formatTime = format.format(new Date(time)); Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); if (formatTime.startsWith(String.valueOf(year))) { return formatTime.substring(5); } else { return formatTime; } } catch (Exception e) { return ""; } }
From source file:Main.java
public static long getUtcMillis(final long millis) { Calendar calendar = getCalendar(millis); long offset = calendar.get(Calendar.ZONE_OFFSET); return millis - offset; }
From source file:Main.java
public static int getYear(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date);/*from www . j a v a2 s. co m*/ return c.get(Calendar.YEAR); }
From source file:Main.java
public static boolean hasYearPassed(int year) { int normalized = normalizeYear(year); Calendar now = Calendar.getInstance(); return normalized < now.get(Calendar.YEAR); }
From source file:Main.java
public static Integer GetMonthNumber(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d);//from w w w . j a va 2 s. c om return cal.get(Calendar.MONTH); }
From source file:Main.java
public static String getCurrentTimeStampHHMMSS() { Calendar cal = new GregorianCalendar(); return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2); }
From source file:Main.java
public static String getOrdinalDayOfMonth(Calendar cal) { int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); return String.valueOf(dayOfMonth) + getDayOfMonthSuffix(dayOfMonth); }
From source file:Main.java
public static int getWeekdayOfMonth(Calendar c) { Calendar cal = (Calendar) c.clone(); cal.set(Calendar.DATE, 1);/*from ww w. j a v a 2 s . com*/ return cal.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:Main.java
public static String getCurrentTimeStampDD_MM_YYYY() { Calendar cal = new GregorianCalendar(); return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4); }