List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
/** * Convert date from String to Xml GregorianCalendar in this 'MM/dd/yyyy hh:mm:ss' * @param s/*ww w. ja v a2 s . c o m*/ * @return * @throws DatatypeConfigurationException * @throws ParseException */ public static XMLGregorianCalendar stringToXMLGregorianCalendar(String s) throws DatatypeConfigurationException, ParseException { if (s != null && !(s.trim().length() < 1)) { XMLGregorianCalendar result = null; Date date; SimpleDateFormat simpleDateFormat; GregorianCalendar gregorianCalendar; simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss"); date = simpleDateFormat.parse(s); gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); gregorianCalendar.setTime(date); result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); return result; } return null; }
From source file:DateUtils.java
public static final String dateToString(Date dt, String tzString, String dateformat) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt); cal.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); String separator = new String(); if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) { separator = "-"; }/*w ww . j a va 2s . co m*/ if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD_SLASHES)) { separator = "/"; } ret.append(cal.get(Calendar.YEAR)); ret.append(separator); ret.append(cal.get(Calendar.MONTH) + 1); ret.append(separator); ret.append(cal.get(Calendar.DATE)); return ret.toString(); }
From source file:com.rogers.ute.creditservice.util.CreditServiceUtils.java
private static XMLGregorianCalendar asXMLGregorianCalendar(String date) { try {/*from w w w . j a v a 2 s. c o m*/ XMLGregorianCalendar result = null; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); /*Date date = simpleDateFormat.parse(date);*/ gregorianCalendar.setTime(simpleDateFormat.parse(date)); result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); return result; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:DateUtils.java
public static final String getTimeFromDate(Date dt, String tzString) { try {/*from w w w . j a va 2 s .c o m*/ GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dt); gc.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); ret.append(gc.get(Calendar.HOUR)); ret.append(":"); ret.append(gc.get(Calendar.MINUTE)); ret.append(" "); if (gc.get(Calendar.AM_PM) == 0) { ret.append("AM"); } else { ret.append("PM"); } return ret.toString(); } catch (Exception e) { return ""; } }
From source file:edu.stanford.muse.email.Filter.java
/** takes current date and converts it to something like 20130709 for July 9 2013 */ private static String dateToString(Date d) { GregorianCalendar c = new GregorianCalendar(); c.setTime(d); int yyyy = c.get(Calendar.YEAR); int mm = c.get(Calendar.MONTH) + 1; // rememeber + 1 adj cos calendar is 0 based int dd = c.get(Calendar.DATE); return String.format("%04d", yyyy) + String.format("%02d", mm) + String.format("%02d", dd); }
From source file:DateUtils.java
public static final String getDateTimeFromDate(Date dt, String tzString) { try {//w ww .ja va 2 s . c om GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dt); gc.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); ret.append(gc.get(Calendar.YEAR)); ret.append("-"); ret.append(gc.get(Calendar.MONTH) - 1); ret.append("-"); ret.append(gc.get(Calendar.DATE)); ret.append(" "); ret.append(gc.get(Calendar.HOUR)); ret.append(":"); ret.append(gc.get(Calendar.MINUTE)); ret.append(" "); if (gc.get(Calendar.AM_PM) == 0) { ret.append("AM"); } else { ret.append("PM"); } return ret.toString(); } catch (Exception e) { return ""; } }
From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java
static XMLGregorianCalendar convert(Date date) { try {/*from w w w .j a v a 2 s.com*/ GregorianCalendar gregDate = (GregorianCalendar) GregorianCalendar.getInstance(); gregDate.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregDate); } catch (Exception e) { return null; } }
From source file:Main.java
public static XMLGregorianCalendar getXMLDate(final Calendar calendar) { GregorianCalendar c; if (calendar instanceof GregorianCalendar) { c = (GregorianCalendar) calendar; } else {//from w w w.j a va 2 s. c o m c = new GregorianCalendar(); c.setTimeZone(UTC); c.setTime(calendar.getTime()); } try { XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); return ret; } catch (DatatypeConfigurationException e) { return null; } }
From source file:org.oscarehr.util.MiscUtils.java
License:asdf
public static GregorianCalendar toCalendar(Date date) { if (date == null) return (null); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); return (cal); }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getNextDateForDay(final DateTime startDate, final int every) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); gc.add(Calendar.DAY_OF_WEEK, every); return new DateTime(gc.getTime().getTime()); }