List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:egovframework.com.utl.wed.filter.DirectoryPathManager.java
/** * 2012/12/22//*from w w w. j av a 2 s . c o m*/ * @param dateType * @return * @throws InvalidArgumentException */ public static String getDirectoryPathByDateType(DIR_DATE_TYPE policy) { Calendar calendar = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(calendar.get(Calendar.YEAR)).append(File.separator); if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH)), 2, '0')) .append(File.separator); } if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM_DD.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)), 2, '0')) .append(File.separator); } return sb.toString(); }
From source file:CalendarDemo.java
public void format() { // Tell the calendar what date/time to format calendar.setTime(timeNow);/*from w w w.j a va 2 s .c o m*/ // print out most of the known fields System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000))); System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000))); }
From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobStatusTransform.java
/** * Enusre that the list contains a date matching Now - the Period. if not add it to the collection *//*from ww w . j ava 2s .c om*/ public static void ensureDateFromPeriodExists(List<JobStatusCount> jobStatusCounts, Period period) { //add in the very first date relative to the period if it doesnt exist with a count of 0 if (jobStatusCounts != null && !jobStatusCounts.isEmpty()) { //get the first min date in the result set Date firstDateInResultSet = jobStatusCounts.stream().map(jobStatusCount -> jobStatusCount.getDate()) .min(Date::compareTo).get(); Date firstDate = DateUtils.truncate(DateTimeUtil.getNowUTCTime().minus(period).toDate(), Calendar.DATE); boolean containsFirstDate = jobStatusCounts.stream() .anyMatch(jobStatusCount -> jobStatusCount.getDate().equals(firstDate)); if (!containsFirstDate) { JobStatusCount first = jobStatusCounts.get(0); JobStatusCount min = new JobStatusCountResult(first); min.setDate(firstDate); min.setCount(new Long(0)); jobStatusCounts.add(min); } } }
From source file:com.appleframework.monitor.model.TimeRangeTest.java
public void test_start() throws Exception { timeRange.setNow(DateUtils.parseDate("2011-11-11 00:00", new String[] { DATE_FORMAT })); timeRange.setLast(1);/* w w w . j a v a 2s . co m*/ timeRange.setUnit(Calendar.HOUR); assertEquals("2011-11-10 23:00", sdf.format(timeRange.getStart())); timeRange.setUnit(Calendar.DATE); assertEquals("2011-11-10 00:00", sdf.format(timeRange.getStart())); }
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();// www.ja va 2s.c om calendar.set(Calendar.DATE, 1); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.YEAR, 1981); date = calendar.getTime(); taskReport.setDate(date); taskReport.setElapsedTime(4); taskReport.setStatus(STATUS); taskReport.setWorkDescription(WORK_DESCRIPTION); list = new ArrayList<TaskReport>(); list.add(taskReport); }
From source file:com.liusoft.dlog4j.util.DateUtils.java
/** * ??/*from w ww . j a v a 2 s . c o m*/ * @param year * @param month * @param date * @return */ public static Calendar getDateBegin(int year, int month, int date) { Calendar begin_time = Calendar.getInstance(); begin_time.set(Calendar.YEAR, year); begin_time.set(Calendar.MONTH, month - 1); begin_time.set(Calendar.DATE, date); begin_time.set(Calendar.HOUR_OF_DAY, 0); begin_time.set(Calendar.MINUTE, 0); begin_time.set(Calendar.SECOND, 0); begin_time.set(Calendar.MILLISECOND, 0); return begin_time; }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Calendar getCalendar(String yyyy, String mm, String dd) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.valueOf(yyyy)); cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1); cal.set(Calendar.DATE, Integer.valueOf(dd)); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/*from w ww . j a va 2s . c o m*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:com.thruzero.common.core.utils.DateTimeFormatUtilsExt.java
/** Return the {@code Calendar.DATE} portion of the given {@code dateTime}. */ public static Date truncateTime(final Date dateTime) { return DateUtils.truncate(dateTime, Calendar.DATE); }
From source file:de.tklerx.dao.Player.java
public Player(String playerName, String missedDate, String team, String history, String teamLink) throws ParseException { super();/*w ww . ja v a2 s .c o m*/ this.playerName = playerName; Date date = DateUtils.parseDateStrictly(missedDate, new String[] { "dd.MM.yy HH:mm" }); c.setTime(date); c.add(Calendar.DATE, 1); this.missedDate = c.getTime(); this.team = team; this.history = history; this.teamLink = teamLink; }
From source file:helper.lang.DateHelperTest.java
@Test public void testAsUtcDayCalendar() { Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST")); Calendar cal = DateHelper.asUtcDay(localTime); assertEquals(0, cal.get(Calendar.MILLISECOND)); assertEquals(0, cal.get(Calendar.MINUTE)); assertEquals(0, cal.get(Calendar.HOUR)); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone()); assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone()); assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR)); assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH)); assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE)); }