List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:Main.java
public static String timeFormat(Date date, String format) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date);//from w w w .j a va 2 s . co m java.text.SimpleDateFormat fm = null; if (format != null) { fm = new java.text.SimpleDateFormat(format); } else { fm = new java.text.SimpleDateFormat(DEFAULT_FORMAT); } return fm.format(gc.getTime()); }
From source file:Main.java
static Calendar toNextWholeHour(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());/* ww w .j av a 2s.c o m*/ c.add(Calendar.HOUR, 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
public static int dayOfWeek() { GregorianCalendar g = new GregorianCalendar(); int ret = g.get(java.util.Calendar.DAY_OF_WEEK); g = null;/* w ww .j a v a 2 s . c om*/ return ret; }
From source file:ConversionUtil.java
/** * convert into java.sql.Time (or into java.util.Calendar * //from w w w . j a v a2s. c om * @param date * The date containing the time. * @param am * Whether this should be am (true) or pm (false) * @return */ public static Time convertDateToTime(Date date, boolean am) { if (date == null) { return null; } Calendar cal = new GregorianCalendar(); cal.setTime(date); int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); if (am) { // Check to make sure that the hours are indeed am hours if (hourOfDay > 11) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay - 12); date.setTime(cal.getTimeInMillis()); } } else { // Check to make sure that the hours are indeed pm hours if (cal.get(Calendar.HOUR_OF_DAY) < 11) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay + 12); date.setTime(cal.getTimeInMillis()); } } return new Time(date.getTime()); }
From source file:Main.java
public static XMLGregorianCalendar toXmlDate(Date date) { try {//from w w w .j a v a 2 s .c o m GregorianCalendar c = new GregorianCalendar(); c.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); } catch (DatatypeConfigurationException dtce) { throw new UnsupportedOperationException("Nemohu prevest " + "GregorianCalendar na XMLGregorianCalendar", dtce); } }
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
/** * Converts a {@link Date} into a {@link XMLGregorianCalendar} * /* w ww . j a v a 2 s .co m*/ * @param date * the date to be converted * @return the XMLGregorianCalendar representing the date converted * @throws DatatypeConfigurationException */ public static XMLGregorianCalendar getXMLGregorianCalendarFromDate(Date date) throws DatatypeConfigurationException { XMLGregorianCalendar retObj = null; if (date != null) { GregorianCalendar gregCal = new GregorianCalendar(); gregCal.setTime(date); retObj = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal); } return retObj; }
From source file:Main.java
public static int getDay(String strDate, String format) { int day = 0;/*w w w .ja v a 2s. c om*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); day = c.get(Calendar.DAY_OF_MONTH); } catch (Exception e) { e.printStackTrace(); } return day; }
From source file:Main.java
public static int getMonth(String strDate, String format) { int month = 0; try {/*from w ww.j ava2s . c om*/ Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); month = c.get(Calendar.MONTH) + 1; } catch (Exception e) { e.printStackTrace(); } return month; }
From source file:Main.java
public static int getWeekNumber(String strDate, String inFormat) { Calendar calendar = new GregorianCalendar(); DateFormat df = new SimpleDateFormat(inFormat); try {/* www.ja v a 2 s . c om*/ calendar.setTime(df.parse(strDate)); } catch (Exception e) { return -1; } int intTemp = calendar.get(Calendar.DAY_OF_WEEK) - 1; return intTemp; }