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 XMLGregorianCalendar convertDateToXmlDate(Date date) { try {/* ww w . jav a2 s .com*/ GregorianCalendar fromDate = new GregorianCalendar(); fromDate.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(fromDate); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Date getDateAdd(Date date, int amount) { Calendar cal = new GregorianCalendar(); cal.setTime(date);// w w w. j a v a2 s . com cal.add(GregorianCalendar.DATE, amount); return cal.getTime(); }
From source file:Main.java
/** * Returns date before given days//from w w w. j a v a 2 s . c o m * * @param days days to before * @return string date string before days */ public static String getDateBefore(int days) { Date today = new Date(); Calendar cal = new GregorianCalendar(); cal.setTime(today); cal.add(Calendar.DAY_OF_MONTH, days * -1); Date date = cal.getTime(); SimpleDateFormat gmtFormat = new SimpleDateFormat(); gmtFormat.applyPattern("yyyy-MM-dd 00:00:00"); TimeZone gmtTime = TimeZone.getTimeZone("GMT"); gmtFormat.setTimeZone(gmtTime); return gmtFormat.format(date); }
From source file:DateUtils.java
/** * A method to get the current date to use in a timestamp * * @return a string containing the timestamp */// w w w.j a v a 2 s. co m public static String getCurrentDate() { GregorianCalendar calendar = new GregorianCalendar(); DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL); return formatter.format(calendar.getTime()); }
From source file:DateUtils.java
/** * A method to get the current date and time to use in a timestamp * * @return a string containing the timestamp *//*from www .ja v a 2 s . c o m*/ public static String getCurrentDateAndTime() { GregorianCalendar calendar = new GregorianCalendar(); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); return formatter.format(calendar.getTime()); }
From source file:Main.java
public static String getStringByFormat(String strDate, String format, String outFormat) { String mDateTime = null;//from www . j a va2 s.c o m try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(outFormat); mDateTime = mSimpleDateFormat2.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
/** * Gets the XML Gregorian calendar from date. * * @param date the date.//from w w w.j a v a 2 s .c om * * @return the XML Gregorian calendar. */ public static XMLGregorianCalendar getXMLDate(Date date) { DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(date.getTime()); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:Main.java
public static XMLGregorianCalendar long2XMLGregorian(long dateAsLong) { DatatypeFactory dataTypeFactory; try {//from w w w . j a v a 2 s. co m dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(dateAsLong); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:DateUtils.java
/** * A method to get the current date as an array of components * 0 = year, 1 = month, 2 = day//from w ww .j a v a 2 s. com * * @return an array of strings representing the current date */ public static String[] getCurrentDateAsArray() { GregorianCalendar calendar = new GregorianCalendar(); String[] fields = new String[3]; fields[0] = Integer.toString(calendar.get(Calendar.YEAR)); fields[1] = String.format("%02d", calendar.get(Calendar.MONTH) + 1); fields[2] = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH)); return fields; }
From source file:Main.java
public static XMLGregorianCalendar parse(long time, int timezone) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time);//from w w w. j a v a 2 s. c o m XMLGregorianCalendar xCal = null; try { xCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); xCal.setTimezone(timezone); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return xCal; }