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 Date toNearestWholeMinute(Date d) { Calendar c = new GregorianCalendar(); c.setTime(d);/* w w w. jav a 2 s .c o m*/ if (c.get(Calendar.SECOND) >= 30) c.add(Calendar.MINUTE, 1); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); }
From source file:Main.java
static float getDatePlg() { Calendar c = new GregorianCalendar(); int y = c.get(Calendar.YEAR); int m = 1 + c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); return getDatePlg(y, m, d); }
From source file:Main.java
public static long currentMonthInMills() { GregorianCalendar gregoriancalendar = new GregorianCalendar(); GregorianCalendar gregoriancalendar1 = new GregorianCalendar(gregoriancalendar.get(1), gregoriancalendar.get(2), 1); gregoriancalendar1.setTimeZone(GMT); return gregoriancalendar1.getTimeInMillis(); }
From source file:Main.java
public static long currentWeekInMills() { GregorianCalendar gregoriancalendar = new GregorianCalendar(); GregorianCalendar gregoriancalendar1 = new GregorianCalendar(gregoriancalendar.get(1), gregoriancalendar.get(2), gregoriancalendar.get(5)); gregoriancalendar1.setTimeZone(GMT); gregoriancalendar1.add(6, -(gregoriancalendar.get(7) - gregoriancalendar.getFirstDayOfWeek())); return gregoriancalendar1.getTimeInMillis(); }
From source file:Main.java
public static XMLGregorianCalendar toXmlDate(Date from) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(from);/* w w w. j av a2 s . c o m*/ try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static GregorianCalendar calendarFromBytes(byte[] buffer, int offset) { if (offset + 5 > buffer.length) return null; GregorianCalendar cal = new GregorianCalendar(); cal.set(buffer[offset] + 2000, buffer[offset + 1], buffer[offset + 2], buffer[offset + 3], buffer[offset + 4], buffer[offset + 5]); return cal;/* ww w . j a v a 2 s . c o m*/ }
From source file:Main.java
public static String timeFormat(long date, String format) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(new Date(date)); java.text.SimpleDateFormat fm = null; if (format != null) { fm = new java.text.SimpleDateFormat(format); } else {// ww w .j a v a2 s . c o m fm = new java.text.SimpleDateFormat(DEFAULT_FORMAT); } return fm.format(gc.getTime()); }
From source file:Main.java
public static XMLGregorianCalendar convertDate(Date date) { try {//from w w w . ja v a 2 s. c om Calendar c = new GregorianCalendar(); c.setTime(date); XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH)); xmlGregorianCalendar.setYear(c.get(Calendar.YEAR)); return xmlGregorianCalendar; } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:Main.java
protected static XMLGregorianCalendar getCurrentTime() { return datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()); }
From source file:Main.java
public static String getDateByAddHour(String datetime, int minute) { String returnTime = null;//from w ww. j a v a 2s.c om Calendar cal = new GregorianCalendar(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date; try { date = ft.parse(datetime); cal.setTime(date); cal.add(GregorianCalendar.MINUTE, minute); returnTime = getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } return returnTime; }