List of usage examples for java.util Calendar MONTH
int MONTH
To view the source code for java.util Calendar MONTH.
Click Source Link
get
and set
indicating the month. From source file:Main.java
public static String getDateTimeString(Calendar calendar) { int year = calendar.get(Calendar.YEAR); // if (year>3900) year-=1900; SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault()); //Date date = new Date(); return dateFormat .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static Integer GetMonthNumber(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d); return cal.get(Calendar.MONTH); }
From source file:Main.java
public static String getDateTime(Calendar calendar) { int year = calendar.get(Calendar.YEAR); // if (year>3900) year-=1900; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); //Date date = new Date(); return dateFormat .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static String getCurrent() { Calendar calender = Calendar.getInstance(); String minute = ""; if (calender.get(Calendar.MINUTE) < 10) { minute = 0 + "" + calender.get(Calendar.MINUTE); } else {/*from ww w .j a va 2 s . co m*/ minute = "" + calender.get(Calendar.MINUTE); } String created = calender.get(Calendar.YEAR) % 100 + "/" + (calender.get(Calendar.MONTH) + 1) + "/" + calender.get(Calendar.DAY_OF_MONTH) + " " + calender.get(Calendar.HOUR_OF_DAY) + ":" + minute + ""; return created; }
From source file:Main.java
public static String getDateFromUTC(long timestamp) { if (timestamp == 0) timestamp = System.currentTimeMillis(); Date date = new Date(timestamp); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTime(date);//from w w w . jav a 2 s .c o m String val = (cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + (cal.get(Calendar.AM_PM) == 0 ? "AM" : "PM")); // final Date currentTime = new Date(); // final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z"); // sdf.setTimeZone(TimeZone.getTimeZone("UTC")); // String ret = "UTC time: " + sdf.format(currentTime); // System.out.println(ret); return val; }
From source file:Main.java
public static String getCurrentTimeStampYYYY_MM_DD_HH_MM_SS() { Calendar cal = new GregorianCalendar(); return makeTimeString(cal.get(Calendar.YEAR), 4) + "/" + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "/" + makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + " " + 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 long CompareTimeDelta(String arrivalTime) { Calendar calendarToday = Calendar.getInstance(); Calendar calendarTrainArrival = Calendar.getInstance(); long millisecondsCurrent = calendarToday.getTimeInMillis(); long millisecondsTrainArrival; int nowYear = calendarToday.get(Calendar.YEAR); int nowMonth = calendarToday.get(Calendar.MONTH); int nowDay = calendarToday.get(Calendar.DATE); int evalhr = 0; int evalmin = 0; int evalsec = 0; String delims = "[:]"; String[] timesplit = arrivalTime.split(delims); evalhr = Integer.parseInt(timesplit[0]); //HR evalmin = Integer.parseInt(timesplit[1]); //MIN evalsec = Integer.parseInt(timesplit[2]); //SEC - VRE does not provide a schedule down to seconds, so ignore. calendarTrainArrival.set(nowYear, nowMonth, nowDay, evalhr, evalmin); millisecondsTrainArrival = calendarTrainArrival.getTimeInMillis(); return millisecondsCurrent - millisecondsTrainArrival; }
From source file:Main.java
public static String getCurrentTimeStamp() { 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) + " " + 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 int getDaylightSavingsTimeOffset(long timeMs) { int dstOffset = 5; // default not daylight savings time Calendar c = Calendar.getInstance(); c.setTimeInMillis(timeMs);/*from ww w . j av a2 s .c om*/ int day = c.get(Calendar.DATE); int month = c.get(Calendar.MONTH); if ((month > DST_START_MONTH && month < DST_END_MONTH) || (month == DST_START_MONTH && day >= DST_START_DAY) || (month == DST_END_MONTH && day <= DST_END_DAY)) { dstOffset = 4; } return dstOffset; }
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); }