List of usage examples for java.util GregorianCalendar GregorianCalendar
GregorianCalendar(TimeZone zone, Locale locale, boolean flag)
From source file:Main.java
/** * Calculates the difference in days, rounding the operands down to the nearest day. * Ex. Jan 3rd 12:31 pm - Jan 2nd 4:00 pm * = Jan 3rd - Jan 2nd//from www. ja v a 2 s . com * = 1 day * @return The difference in days. */ public static int differenceInDays(GregorianCalendar minuend, GregorianCalendar subtrahend) { GregorianCalendar minuendFloor = new GregorianCalendar(minuend.get(Calendar.YEAR), minuend.get(Calendar.MONTH), minuend.get(Calendar.DAY_OF_MONTH)); GregorianCalendar subtrahendFloor = new GregorianCalendar(subtrahend.get(Calendar.YEAR), subtrahend.get(Calendar.MONTH), subtrahend.get(Calendar.DAY_OF_MONTH)); GregorianCalendar result = new GregorianCalendar(); result.setTimeInMillis(minuendFloor.getTimeInMillis() - subtrahendFloor.getTimeInMillis()); return result.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
/** * //from www. j a v a 2s .c o m * @param date * @return */ public static Date getDate(String date) { if ("".equals(date) || date == null || "null".equals(date)) { return null; } else { String[] obj = date.split("-"); int year = Integer.valueOf((String) obj[0]).intValue(); int month = Integer.valueOf((String) obj[1]).intValue(); int day = Integer.valueOf((String) obj[2]).intValue(); Calendar calendar = new GregorianCalendar(year, month - 1, day); return calendar.getTime(); } }
From source file:Main.java
public static Calendar getRandomDate(int baseYear) { synchronized (rand) { Calendar today = Calendar.getInstance(); int year = rand.nextInt(today.get(Calendar.YEAR) - baseYear + 1) + baseYear; int month = year == today.get(Calendar.YEAR) ? rand.nextInt(today.get(Calendar.MONTH) - 1) + 1 : rand.nextInt(12) + 1;// w w w . ja va2s . co m int day = year == today.get(Calendar.YEAR) ? rand.nextInt(today.get(Calendar.DAY_OF_WEEK)) + 1 : rand.nextInt(29) + 1; return new GregorianCalendar(year, month, day); } }
From source file:Main.java
public static Date convertDate(XMLGregorianCalendar date) { return new GregorianCalendar(date.getYear(), date.getMonth(), date.getDay()).getTime(); }
From source file:Main.java
/** * Convert "YYYY-MM-DD" to "Friday X Month Year" * /* www .j a v a2s .c om*/ * @param Date_In * @param conf * @return */ public static String dateNum2STR(String Date_In, Configuration conf) { String DayNo_STR = Date_In.substring(8, 10); int DayNo = Integer.parseInt(DayNo_STR); String MonthNo_STR = Date_In.substring(5, 7); int MonthNo = Integer.parseInt(MonthNo_STR); String Month_STR = formatMonth(Integer.parseInt(MonthNo_STR), conf.locale); String Year_STR = Date_In.substring(0, 4); int Year = Integer.parseInt(Year_STR); Calendar myCal = new GregorianCalendar(Year, MonthNo - 1, DayNo); int dayOfWeek = myCal.get(Calendar.DAY_OF_WEEK); // 6=Friday String dayOfWeek_STR = DateUtils.getDayOfWeekString(dayOfWeek, DateUtils.LENGTH_MEDIUM); return dayOfWeek_STR + " " + DayNo_STR + " " + Month_STR + " " + Year_STR; }
From source file:org.makersoft.activesql.unit.MyBatisTest.java
private static User buildUser() { User user = new User(); user.setUserName("makersoft"); user.setPassword("password"); user.setBirthDay(new GregorianCalendar(1987, 12, 25).getTime()); user.setCreatedAt(new Date()); user.setUpdatedAt(new Date()); return user;/*ww w. j av a 2 s . c om*/ }
From source file:DynaBeansExampleV1.java
private static Object createMovieBean() throws Exception { // first create the properties DynaProperty properties[] = new DynaProperty[] { new DynaProperty("title", String.class), new DynaProperty("dateOfRelease", Date.class), new DynaProperty("keywords", String[].class), new DynaProperty("genre", Map.class), new DynaProperty("actors", List.class), new DynaProperty("director", DynaBean.class) }; // next using the properties define the class DynaClass movieClass = new BasicDynaClass("movie", null, properties); // now, with the class, create a new instance DynaBean movieBean = movieClass.newInstance(); // set its properties movieBean.set("title", "The Italian Job"); movieBean.set("dateOfRelease", new GregorianCalendar(1969, 0, 1).getTime()); movieBean.set("keywords", new String[] { "Italy", "Bank Robbery" }); Map genre = new HashMap(); genre.put("THR", "Thriller"); movieBean.set("genre", genre); movieBean.set("genre", "ACT", "Action"); DynaBean director = createPersonBean(); director.set("name", "Peter Collinson"); director.set("gender", new Integer(1)); movieBean.set("director", director); return movieBean; }
From source file:BeanUtilsExampleV5.java
private Movie prepareData() { Movie movie = new Movie(); movie.setTitle("The Italian Job"); movie.setDateOfRelease(new GregorianCalendar(2000, 0, 1).getTime()); return movie;//from w ww. j a va2 s.co m }
From source file:ch.wscr.management.WscrManagementApplicationTests.java
@Test public void storeMemberTest() { Member memberToSave = new Member(); memberToSave.setFirstName("Marco"); memberToSave.setLastName("Nitschke"); memberToSave.setBirthDate(new Date(new GregorianCalendar(1977, Calendar.JANUARY, 20).getTimeInMillis())); memberToSave.setAdrStreet("Rilkeweg 9"); memberToSave.setAdrPostalCode("70771"); memberToSave.setAdrCity("Echterdingen"); memberToSave.setDriverLicense(true); memberToSave.setAdrCountry(Country.DE); Member memberSaved = memberRepository.save(memberToSave); assertThat(memberSaved.getMemberId(), is(1)); }
From source file:ch.silviowangler.dox.LoadIntegrationTest.java
@Before public void setUp() throws Exception { loginAsTestRoot();//from ww w . j av a 2 s .c om Calendar calendar = new GregorianCalendar(2013, Calendar.JANUARY, 1); Map<String, SortedSet<Attribute>> cache = new HashMap<>(); for (int i = 1; i <= TOTAL_AMOUNT_OF_FILES; i++) { Map<TranslatableKey, DescriptiveIndex> indices = new HashMap<>(); SortedSet<Attribute> attributes; if (!cache.containsKey("INVOICE")) { attributes = documentService.findAttributes(new DocumentClass("INVOICE")); cache.put("INVOICE", attributes); } else { attributes = cache.get("INVOICE"); } for (Attribute attribute : attributes) { if (!attribute.isOptional()) { Object o; switch (attribute.getDataType()) { case SHORT: case LONG: case DOUBLE: case STRING: case INTEGER: o = Integer.toString(i); break; case BOOLEAN: o = (i % 2 == 0); break; case DATE: calendar.add(Calendar.DAY_OF_YEAR, 1); o = calendar.getTime(); break; case CURRENCY: o = "CHF " + i; break; default: throw new IllegalArgumentException("Unknown attribute type: " + attribute.getDataType()); } indices.put(new TranslatableKey(attribute.getShortName()), new DescriptiveIndex(o)); } } importFile(i + ".txt", Integer.toString(i), "INVOICE", indices); } loginAsTestRoot(); }