List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:Main.java
private static final Calendar getUtcDate(int year, int month, int dayOfMonth) { final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US); calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); return calendar; }
From source file:Main.java
/** * Set the provided calendar to the first day of the month. Also clears all time information. * * @param calendar {@linkplain Calendar} to modify to be at the first fay of the month *//*from w w w . j a v a2s .com*/ public static void setToFirstDay(Calendar calendar) { int year = getYear(calendar); int month = getMonth(calendar); calendar.clear(); calendar.set(year, month, 1); }
From source file:Main.java
/** Helper method - creates a <I>Date</I> object from the date string found in Phoenix XML documents./*w w w. ja v a 2 s .c o m*/ @param strXMLDate Date <I>String</I> from an XML document that follows the format "YYYY-MM-DDTHH:NN:SS.00000". @return <I>Date</I> object. */ public static Date getDateFromXMLString(String strXMLDate) throws IllegalArgumentException { if (null == strXMLDate) return null; int nLength = strXMLDate.length(); if (10 > nLength) throw new IllegalArgumentException( "XML date value (" + strXMLDate + ") is not of the expected format (yyyy-mm-ddThh:nn:ss)."); // Create date object from timestamp string. try { Calendar pCalendar = Calendar.getInstance(); pCalendar.clear(); int nHour = 0; int nMinute = 0; int nSecond = 0; if (13 <= nLength) nHour = Integer.parseInt(strXMLDate.substring(11, 13)); if (16 <= nLength) nMinute = Integer.parseInt(strXMLDate.substring(14, 16)); if (19 <= nLength) nSecond = Integer.parseInt(strXMLDate.substring(17, 19)); pCalendar.set(Integer.parseInt(strXMLDate.substring(0, 4)), Integer.parseInt(strXMLDate.substring(5, 7)) - 1, Integer.parseInt(strXMLDate.substring(8, 10)), nHour, nMinute, nSecond); return pCalendar.getTime(); } catch (NumberFormatException pEx) { throw new IllegalArgumentException( "XML date value (" + strXMLDate + ") is not of the expected format (yyyy-mm-ddThh:nn:ss)."); } }
From source file:Main.java
/** * Converts an XMLGregorianCalendar to a Date. * * @param xmlDate/*from ww w .j a v a2 s .co m*/ * XMLGregorianCalendar to convert. * @return corresponding date object. */ public static Date getDate(final XMLGregorianCalendar xmlDate) { // TODO: is this equivalent to getDate(String) processing above?? // start with UTC, i.e. no daylight savings time. TimeZone timezone = TimeZone.getTimeZone("GMT"); // adjust timezone to match xmldate int offsetMinutes = xmlDate.getTimezone(); if (offsetMinutes != DatatypeConstants.FIELD_UNDEFINED) { timezone.setRawOffset( // convert minutes to milliseconds offsetMinutes * 60 // seconds per minute * 1000 // milliseconds per second ); } // use calendar so parsed date will be UTC Calendar calendar = Calendar.getInstance(timezone); calendar.clear(); calendar.set(xmlDate.getYear(), // xmlcalendar is 1 based, calender is 0 based xmlDate.getMonth() - 1, xmlDate.getDay(), xmlDate.getHour(), xmlDate.getMinute(), xmlDate.getSecond()); Date date = calendar.getTime(); int millis = xmlDate.getMillisecond(); if (millis != DatatypeConstants.FIELD_UNDEFINED) { calendar.setTimeInMillis(calendar.getTimeInMillis() + millis); } return date; }
From source file:Main.java
private static Calendar cal(TimeZone tz) { Calendar cal = (tz != null) ? new GregorianCalendar(tz) : new GregorianCalendar(); cal.clear(); return cal;//from w w w. ja v a 2s. co m }
From source file:ru.retbansk.utils.marshaller.Jaxb2MarshallerTest.java
@BeforeClass public static void beforeClass() { TaskReport taskReport = new TaskReport(); Date date = new Date(); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); calendar.clear(); calendar.set(Calendar.DATE, 1); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.YEAR, 1981); date = calendar.getTime();// w ww . j a va 2s .c o m taskReport.setDate(date); taskReport.setElapsedTime(4); taskReport.setStatus(STATUS); taskReport.setWorkDescription(WORK_DESCRIPTION); list = new ArrayList<TaskReport>(); list.add(taskReport); }
From source file:Main.java
/** * Copy <i>only</i> date information to a new calendar. * * @param from calendar to copy from/*w w w. ja va 2 s.co m*/ * @param to calendar to copy to */ public static void copyDateTo(Calendar from, Calendar to) { int year = getYear(from); int month = getMonth(from); int day = getDay(from); to.clear(); to.set(year, month, day); }
From source file:Main.java
/** * Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since * the epoch./*from w ww . j a v a 2 s . c o m*/ * * @param value The attribute value to parse. * @return The parsed timestamp in milliseconds since the epoch. */ public static long parseXsDateTime(String value) throws ParseException { Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value); if (!matcher.matches()) { throw new ParseException("Invalid date/time format: " + value, 0); } int timezoneShift; if (matcher.group(9) == null) { // No time zone specified. timezoneShift = 0; } else if (matcher.group(9).equalsIgnoreCase("Z")) { timezoneShift = 0; } else { timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60 + Integer.parseInt(matcher.group(13)))); if (matcher.group(11).equals("-")) { timezoneShift *= -1; } } Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT")); dateTime.clear(); // Note: The month value is 0-based, hence the -1 on group(2) dateTime.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)), Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6))); if (!TextUtils.isEmpty(matcher.group(8))) { final BigDecimal bd = new BigDecimal("0." + matcher.group(8)); // we care only for milliseconds, so movePointRight(3) dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue()); } long time = dateTime.getTimeInMillis(); if (timezoneShift != 0) { time -= timezoneShift * 60000; } return time; }
From source file:org.spring.data.gemfire.cache.UserDataStoreCacheLoader.java
protected static Calendar createCalendar(final int year, final int month, final int dayOfMonth, final int hourOfDay, final int minute, final int second) { Calendar dateTime = Calendar.getInstance(); dateTime.clear(); dateTime.set(Calendar.YEAR, year); dateTime.set(Calendar.MONTH, month); dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth); dateTime.set(Calendar.HOUR_OF_DAY, dayOfMonth); dateTime.set(Calendar.MINUTE, minute); dateTime.set(Calendar.SECOND, second); return dateTime; }
From source file:Main.java
/** * Copy <i>only</i> date information to a new calendar. * * @param from calendar to copy from// w ww . j a v a2 s .co m * @param to calendar to copy to */ public static void copyDateTo(Calendar from, Calendar to) { int year = getYear(from); int month = getMonth(from); int day = getDay(from); to.clear(); to.set(year, month, day); to.getTimeInMillis(); }