timestamp

Convenience method to setup an XML dateTime (XMLGregorianCalendar) with passed in Date
@param date
@return
320992
public static XMLGregorianCalendar timeStamp(Date date) {
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		return xmlDatatypeFactory.newXMLGregorianCalendar(gc);
	}
179247
public static Date parseDate(final String date) {

        /*
            IE9 sends a superflous lenght parameter after date in the
            If-Modified-Since header, which needs to be stripped before
            parsing.

         */

        final int semicolonIndex = date.indexOf(';');
        final String trimmedDate = semicolonIndex >= 0 ? date.substring(0, semicolonIndex) : date;

        ParsePosition pp = new ParsePosition(0);
        SimpleDateFormat dateFormat = RFC1123_PATTERN_FORMAT.get();
        dateFormat.setTimeZone(GMT_ZONE);
        Date val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        pp = new ParsePosition(0);
        dateFormat = new SimpleDateFormat(RFC1036_PATTERN, LOCALE_US);
        dateFormat.setTimeZone(GMT_ZONE);
        val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        pp = new ParsePosition(0);
        dateFormat = new SimpleDateFormat(ASCITIME_PATTERN, LOCALE_US);
        dateFormat.setTimeZone(GMT_ZONE);
        val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        pp = new ParsePosition(0);
        dateFormat = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
        dateFormat.setTimeZone(GMT_ZONE);
        val = dateFormat.parse(trimmedDate, pp);
        if (val != null && pp.getIndex() == trimmedDate.length()) {
            return val;
        }

        return null;
    }
1316234
static Date convertDate(String date) throws ParseException {
        final int zIndex = date.indexOf('Z');
        if (zIndex - 3 < 0) {
            throw new ParseException(date
                    + " doesn't match the expected subversion date format", date.length());
        }
        String withoutMicroSeconds = date.substring(0, zIndex - 3);

        return getOutDateFormatter().parse(withoutMicroSeconds);
    }
1357796
public static final synchronized Date parseDate(String date) {
		try {
			return dateFormat.parse(date);
		} catch(ParseException e) {
			throw new RuntimeException(e);
		}
	}
83708
public static Date fromJavaUtilDate(java.util.Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    // Calender.MONTH starts from 0 while G C date starts from 1
    return new Date(
        cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH));
  }
281920
public XMLGregorianCalendar getTimeStamp()
   {
       GregorianCalendar cal = new GregorianCalendar();
       DatatypeFactory dt;
       try {
           dt = DatatypeFactory.newInstance();
           return dt.newXMLGregorianCalendar(cal);
       } catch (DatatypeConfigurationException e) {
           e.printStackTrace();
       }
       return null;
   }
234823
public XMLGregorianCalendar buildXMLGregorianCalendarDate(Date date) {
        XMLGregorianCalendar result = null;
        if (date != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            result = buildXMLGregorianCalendarDate(cal);
        }
        return result;
    }
145660
public static Calendar parseXmlDate(String xsDate) throws ParseException {
        try {
            DatatypeFactory df = DatatypeFactory.newInstance();
            XMLGregorianCalendar dateTime = df.newXMLGregorianCalendar(xsDate);
            return dateTime.toGregorianCalendar();
        } catch (DatatypeConfigurationException ex) {
            throw new ParseException("Unable to parse " + xsDate, ex);
        }
    }
1200267
@Nullable
  public static XMLGregorianCalendar getXMLCalendar (@Nullable final Date aDate)
  {
    if (aDate == null)
      return null;
    return s_aDTFactory.newXMLGregorianCalendar (getCalendar (aDate));
  }
62409
public static Value.Builder makeValue(Date date) {
    return Value.newBuilder().setTimestampValue(toTimestamp(date.getTime() * 1000L));
  }
446620
@Override
    public boolean inDaylightTime(Date date){
        GregorianCalendar gc = new GregorianCalendar(this);
        gc.setTime(date);
        return gc.inDaylightTime();
    }
1017224
public String formatDate(Date date, int type)
    {
        String string = null;
        if (type == DBConstants.DATE_TIME_FORMAT)
            string = XmlUtilities.dateTimeFormat.format(date);
        else if (type == DBConstants.DATE_ONLY_FORMAT)
            string = XmlUtilities.dateFormat.format(date);
        else if (type == DBConstants.TIME_ONLY_FORMAT)
            string = XmlUtilities.timeFormat.format(date);
        return string;
    }
1192831
protected Calendar createJavaCalendar (final long timeStamp)
  {
    final Calendar calendar = createJavaCalendar ();
    calendar.setTime (new Date (timeStamp));
    return calendar;
  }
931353
public static DateTime getJodaOrJavaDate(final DateTimeFormatter dateFormatter, final String date) throws Exception {
        if (DateTimeUtils.isDateValid(date, dateFormatter.getLocale())) {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, dateFormatter.getLocale());

            Calendar dateCalendar = GregorianCalendar.getInstance();
            dateCalendar.setTime(dateFormat.parse(date));

            return new DateTime(dateCalendar.getTime());
        }

        return new DateTime(date);
    }
515296
public XMLGregorianCalendar buildXMLGregorianCalendarDate(Calendar cal) {
        XMLGregorianCalendar result = null;
        if (cal != null) {
            result = newXMLGregorianCalendar(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1,
                    cal.get(Calendar.YEAR));
        }
        return result;
    }
991985
public static java.sql.Time getSqlTime(java.util.Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return new java.sql.Time(cal.getTimeInMillis());
    }
638206
public String format(Date date) {
		Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		return DatatypeConverter.printDateTime(cal);
	}