List of usage examples for java.util GregorianCalendar setLenient
public void setLenient(boolean lenient)
From source file:Main.java
public static void main(String[] argv) throws Exception { GregorianCalendar gc = new GregorianCalendar(); gc.setLenient(false); gc.set(GregorianCalendar.YEAR, 2003); gc.set(GregorianCalendar.MONTH, 12); gc.set(GregorianCalendar.DATE, 1); gc.getTime();//from ww w .j a va2s .c om }
From source file:Main.java
public static void main(String[] argv) throws Exception { GregorianCalendar gc = new GregorianCalendar(); gc.setLenient(false); gc.set(GregorianCalendar.YEAR, 2003); gc.set(GregorianCalendar.MONTH, 12); gc.set(GregorianCalendar.DATE, 1); int m = gc.get(GregorianCalendar.MONTH) + 1; int d = gc.get(GregorianCalendar.DATE); String mm = Integer.toString(m); String dd = Integer.toString(d); System.out.println(gc.get(GregorianCalendar.YEAR) + (m < 10 ? "0" + mm : mm) + (d < 10 ? "0" + dd : dd)); }
From source file:Main.java
public static String weekDay(String year, String month, String day) { String strWeekday = ""; try {/*w ww . j a v a 2 s . c om*/ GregorianCalendar cal = new GregorianCalendar(); cal.setLenient(false); cal.clear(); cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); strWeekday = String.valueOf(cal.get(Calendar.DAY_OF_WEEK) - 1); } catch (IllegalArgumentException e) { strWeekday = ""; } return strWeekday; }
From source file:Main.java
public static boolean isPastDate(String year, String month, String day) { try {//from w w w . jav a 2s.c o m GregorianCalendar cal = new GregorianCalendar(); cal.setLenient(false); SimpleDateFormat fmDate = new SimpleDateFormat("yyyyMMdd"); String today = fmDate.format(cal.getTime()); cal.clear(); cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); String inputday = fmDate.format(cal.getTime()); if (inputday.compareTo(today) < 0) { return true; } else { return false; } } catch (IllegalArgumentException e) { return false; } }
From source file:ca.uhn.hl7v2.model.primitive.tests.CommonDTTest.java
/** * Testing toHl7DTFormat() with a calendar *//*from w w w . j ava2 s. c om*/ @Test public void testConvertCalToHL7DateFormat() throws DataTypeException { GregorianCalendar cal = new GregorianCalendar(); cal.clear(); cal.setLenient(false); cal.set(2002, 5, 24); String convertedDate = CommonDT.toHl7DTFormat(cal); assertEquals("20020624", convertedDate); }
From source file:ca.uhn.hl7v2.model.primitive.CommonTSTest.java
@Test public void testToHl7TMFormat() throws DataTypeException { GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("America/Toronto")); cal.clear();/*from w ww . ja v a 2s. c om*/ cal.setLenient(false); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 6); cal.set(Calendar.SECOND, 24); cal.set(Calendar.MILLISECOND, 528); String convertedDate = CommonTM.toHl7TMFormat(cal); assertEquals("Should get a HL7 formatted date back", "200624.528-0500", convertedDate); }
From source file:ca.uhn.hl7v2.model.primitive.tests.CommonTSTest.java
@Test public void testToHl7TMFormat() throws DataTypeException { GregorianCalendar cal = new GregorianCalendar(); cal.clear();//from w ww . j a va 2s. c om cal.setLenient(false); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 6); cal.set(Calendar.SECOND, 24); cal.set(Calendar.MILLISECOND, 528); String convertedDate = CommonTM.toHl7TMFormat(cal); assertEquals("Should get a HL7 formatted date back", "200624.528-0500", convertedDate); }
From source file:org.openmrs.module.pmtct.PregnancyDateManager.java
@SuppressWarnings("deprecation") public String getNumberOfWeeks(String dateOfPeriod) throws Exception { Date lastDateOfPeriod = Context.getDateFormat().parse(dateOfPeriod); GregorianCalendar last_DateOfPeriod = new GregorianCalendar(lastDateOfPeriod.getYear(), lastDateOfPeriod.getMonth(), lastDateOfPeriod.getDate()); last_DateOfPeriod.setLenient(false); Date da = new Date(); // slog.info("xxxxxxxxxxxxxxx"+(new GregorianCalendar(da.getYear()+1900,da.getMonth(),da.getDate())).getTime()); //1 week=604800000 milliseconds = (1000ms*60s*60min*24h*7days) return "**********************" + (((new GregorianCalendar(da.getYear(), da.getMonth(), da.getDate())).getTimeInMillis()) - (last_DateOfPeriod.getTimeInMillis())) / 604800000; }
From source file:org.openmrs.module.pmtct.PregnancyDateManager.java
@SuppressWarnings("deprecation") public String getDPA(String dateOfPeriod) throws Exception { Date lastDateOfPeriod = Context.getDateFormat().parse(dateOfPeriod); GregorianCalendar last_DateOfPeriod = new GregorianCalendar(lastDateOfPeriod.getYear() + 1900, lastDateOfPeriod.getMonth(), lastDateOfPeriod.getDate()); last_DateOfPeriod.setLenient(false); last_DateOfPeriod.add(Calendar.DAY_OF_YEAR, PMTCTConstants.DELAY_IN_DAYS_OF_PREGNANCY); return Context.getDateFormat().format(last_DateOfPeriod.getTime()); }
From source file:stg.utils.immutable.Day.java
private GregorianCalendar getCalendarInstance(TimeZone zone) { GregorianCalendar calendar = new GregorianCalendar(); calendar.clear();/* ww w . j av a 2s. c om*/ calendar.setLenient(false); calendar.setTimeZone(zone); return calendar; }