List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static String format(Date date) { SimpleDateFormat myFmt1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss EEE"); String[] days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; String[] daysFull = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/* w w w . j a v a 2 s . c o m*/ int day = calendar.get(Calendar.DAY_OF_WEEK); int month = calendar.get(Calendar.MONTH); return String .valueOf(days[day - 1] + " " + myFmt1.format(date) + " " + months[month] + " " + daysFull[day - 1]); }
From source file:Main.java
public static boolean inSameDay(Date date1, Date Date2) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date1);//w w w . j a v a 2 s . c o m int year1 = calendar.get(Calendar.YEAR); int day1 = calendar.get(Calendar.DAY_OF_YEAR); calendar.setTime(Date2); int year2 = calendar.get(Calendar.YEAR); int day2 = calendar.get(Calendar.DAY_OF_YEAR); return (year1 == year2) && (day1 == day2); }
From source file:Main.java
public static Long GetUTCTime() { Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); int zoneOffset = cal.get(Calendar.ZONE_OFFSET); int dstOffset = cal.get(Calendar.DST_OFFSET); cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset)); return cal.getTimeInMillis(); }
From source file:Main.java
public static Date getLastWeekMonday() { Calendar cal = Calendar.getInstance(); for (int mondays = 0; mondays < 2;) { if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) { mondays++;/*from w ww . j a v a 2 s .c o m*/ } cal.add(Calendar.DAY_OF_WEEK, -1); } return cal.getTime(); }
From source file:eu.trentorise.smartcampus.mobility.processor.alerts.ParkingChecker.java
private static String buildDate() { Calendar cal = new GregorianCalendar(); return cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR); }
From source file:Util.java
public static String formatAsMySQLDatetime(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w. ja v a 2 s .co m int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DATE); int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); int seconds = calendar.get(Calendar.SECOND); return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds; }
From source file:Main.java
public static int getDayFromDate(String origDate) { DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); Date date;//www .j a va2 s .c o m int day = 1; try { date = formatter.parse(origDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); day = cal.get(Calendar.DAY_OF_MONTH); } catch (ParseException e) { e.printStackTrace(); } return day; }
From source file:Main.java
private static Date getTomorrowMorning4am() { Calendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DATE, fONE_DAY); Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR), tomorrow.get(Calendar.MONTH), tomorrow.get(Calendar.DATE), fFOUR_AM, fZERO_MINUTES); return result.getTime(); }
From source file:Main.java
public static int getFirstDayOfWeek(Date date) { int n = getDayOfWeek(date); Calendar c = Calendar.getInstance(); c.setTime(date);/* w w w . ja v a 2s .c om*/ c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - n + 1); return c.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
private static boolean isSameAmPm(long start, long end) { Calendar starting = calendarByMillis(start); Calendar ending = calendarByMillis(end); return starting.get(Calendar.AM_PM) == ending.get(Calendar.AM_PM); }