List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:TimeLib.java
/** * Get the number of time units between the two given timestamps. * @param t0 the first timestamp (as a long) * @param t1 the second timestamp (as a long) * @param field the time unit to use, one of the {@link java.util.Calendar} * fields, or one of the extended fields provided by this class * (MILLENIUM, CENTURY, or DECADE).//from w ww. ja v a 2 s . c o m * @return the number of time units between the two timestamps */ public static int getUnitsBetween(long t0, long t1, int field) { boolean negative = false; if (t1 < t0) { long tmp = t1; t1 = t0; t0 = tmp; // swap negative = true; } GregorianCalendar gc1 = new GregorianCalendar(); GregorianCalendar gc2 = new GregorianCalendar(); gc1.setTimeInMillis(t0); gc2.setTimeInMillis(t1); // add 2 units less than the estimate to 1st date, // then serially add units till we exceed 2nd date int est = estimateUnitsBetween(t0, t1, field); boolean multiYear = isMultiYear(field); if (multiYear) { gc1.add(Calendar.YEAR, -field * (est - 2)); est = -field * est; } else { gc1.add(field, est - 2); } int f = multiYear ? Calendar.YEAR : field; int inc = multiYear ? -field : 1; for (int i = est - inc;; i += inc) { gc1.add(f, inc); if (gc1.after(gc2)) { return negative ? inc - i : i - inc; } } }
From source file:com.esofthead.mycollab.common.interceptor.aspect.InjectTimeLoggingAspect.java
@Before("execution(public * com.esofthead.mycollab..service..*.saveWithSession(..)) && args(bean, username)") public void injectDateForSaveMethod(JoinPoint joinPoint, Object bean, String username) { try {//from w w w. j a v a2 s . com LOG.debug("Set createtime and lastupdatedtime if enable"); PropertyUtils.setProperty(bean, "createdtime", new GregorianCalendar().getTime()); PropertyUtils.setProperty(bean, "lastupdatedtime", new GregorianCalendar().getTime()); } catch (Exception e) { } }
From source file:net.orpiske.dcd.dispatcher.impl.WebServicesConversor.java
private static XMLGregorianCalendar newXmlGregorianCalendar(final Date date) { GregorianCalendar reportDate = new GregorianCalendar(); reportDate.setTime(date);//w ww. j a v a 2 s . com XMLGregorianCalendar ret = null; try { ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(reportDate); } catch (DatatypeConfigurationException e) { logger.error("Unable to properly transform a date for XML data transfer: " + e.getMessage(), e); } return ret; }
From source file:de.forsthaus.backend.dao.impl.ChartDataDAOImpl.java
@Override public List<ChartData> getChartDataForCustomer(long kunId) { List<ChartData> result = new ArrayList<ChartData>(); if (kunId == 20) { Calendar calendar = new GregorianCalendar(); calendar.set(2009, Calendar.JANUARY, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(120.30))); calendar.set(2009, Calendar.FEBRUARY, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(450.30))); calendar.set(2009, Calendar.MARCH, 15, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(820.10))); calendar.set(2009, Calendar.APRIL, 20, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(654.00))); calendar.set(2009, Calendar.MAY, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(120.30))); calendar.set(2009, Calendar.JUNE, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(520.30))); calendar.set(2009, Calendar.JULY, 22, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(320.30))); calendar.set(2009, Calendar.AUGUST, 13, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(20.30))); calendar.set(2009, Calendar.SEPTEMBER, 6, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(480.30))); calendar.set(2009, Calendar.OCTOBER, 26, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(520.30))); calendar.set(2009, Calendar.NOVEMBER, 26, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(620.70))); calendar.set(2009, Calendar.DECEMBER, 26, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(1220.90))); } else if (kunId == 21) { Calendar calendar = new GregorianCalendar(); calendar.set(2009, Calendar.JANUARY, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(320.30))); calendar.set(2009, Calendar.FEBRUARY, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(450.30))); calendar.set(2009, Calendar.MARCH, 15, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(620.10))); calendar.set(2009, Calendar.APRIL, 20, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(154.00))); calendar.set(2009, Calendar.MAY, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(320.30))); calendar.set(2009, Calendar.JUNE, 2, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(620.30))); calendar.set(2009, Calendar.JULY, 22, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(920.30))); calendar.set(2009, Calendar.AUGUST, 13, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(120.30))); calendar.set(2009, Calendar.SEPTEMBER, 6, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(680.30))); calendar.set(2009, Calendar.OCTOBER, 26, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(580.30))); calendar.set(2009, Calendar.NOVEMBER, 26, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(820.70))); calendar.set(2009, Calendar.DECEMBER, 26, 0, 0, 0); result.add(new ChartData(kunId, calendar.getTime(), new BigDecimal(220.90))); }// www . j a v a 2 s.co m return result; }
From source file:com.sudoku.data.model.User.java
public User(String pseudo, String brutPassword, Date birthDate, String profilePicturePath) throws NoSuchAlgorithmException, UnsupportedEncodingException, UnknownHostException { MessageDigest mDigest = MessageDigest.getInstance("SHA-256"); Calendar cal = new GregorianCalendar(); this.pseudo = pseudo; this.salt = this.randomSalt(); String toBeHashed = brutPassword + this.getSalt(); String hashed = new String(Base64.encode(mDigest.digest(toBeHashed.getBytes("UTF-8")))); this.password = hashed; this.birthDate = birthDate; this.profilePicturePath = profilePicturePath; this.createDate = cal.getTime(); this.updateDate = this.createDate; this.ipAddress = InetAddress.getLocalHost().getHostAddress(); this.contactCategories = new LinkedList<>(); System.out.println(this.getPassword()); }
From source file:Main.java
private static GregorianCalendar gmtStringToGregorianCalendar(String stringTypeDate) throws DatatypeConfigurationException { String yyyy = stringTypeDate.substring(0, 4); String mm = stringTypeDate.substring(5, 7); String dd = stringTypeDate.substring(8, 10); String hh = "00"; String mi = "00"; String ss = "00"; String ms = "00"; String tz = null;/*www.j a va2s . c om*/ if (stringTypeDate.length() > 23) { hh = stringTypeDate.substring(11, 13); mi = stringTypeDate.substring(14, 16); ss = stringTypeDate.substring(17, 19); ms = stringTypeDate.substring(20, 23); tz = stringTypeDate.substring(23); } else { tz = stringTypeDate.substring(10); //tz = "+09:00"; } if (tz.equals("Z")) { tz = "UTC"; } else { tz = "GMT" + tz; } int iyyyy = Integer.parseInt(yyyy); int imm = Integer.parseInt(mm) - 1; int idd = Integer.parseInt(dd); int ihh = Integer.parseInt(hh); int imi = Integer.parseInt(mi); int iss = Integer.parseInt(ss); int ims = Integer.parseInt(ms); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone(tz)); c.set(iyyyy, imm, idd, ihh, imi, iss); c.set(Calendar.MILLISECOND, ims); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(c.getTime()); cal.setTimeZone(TimeZone.getTimeZone("ROK")); return cal; }
From source file:edu.umm.radonc.ca_dash.controllers.D3PieChartController.java
public D3PieChartController() { endDate = new Date(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(endDate);/*w w w. java2 s. c o m*/ gc.add(Calendar.MONTH, -1); startDate = gc.getTime(); interval = "1m"; this.df = new SimpleDateFormat("MM/dd/YYYY"); this.selectedFacility = new Long(-1); this.dstats = new SynchronizedDescriptiveStatistics(); this.interval = ""; selectedFilters = new ArrayList<>(); jsonData = new JSONArray(); }
From source file:no.dusken.aranea.service.PageServiceImpl.java
public List<Page> getSectionPagePublished(int numberOfPages, Section section) { List<Page> pages = Collections.emptyList(); try {//from w w w . jav a2 s . co m Map<String, Object> map = new HashMap<String, Object>(); map.put("time", new GregorianCalendar()); map.put("section", section); pages = genericDao.getByNamedQuery("page_bysection_published", map, 0, numberOfPages); } catch (DataAccessException e) { log.error("Unable to get pages by section", e); } return pages; }
From source file:HSSFDateUtil.java
/** * Given a Date, converts it into a double representing its internal Excel * representation, which is the number of days since 1/1/1900. Fractional days * represent hours, minutes, and seconds. * /*from ww w . jav a 2 s . c o m*/ * @return Excel representation of Date (-1 if error - test for error by * checking for less than 0.1) * @param date * the Date */ public static double getExcelDate(final Date date) { Calendar calStart = new GregorianCalendar(); calStart.setTime(date); // If date includes hours, minutes, and seconds, set // them to 0 // if (calStart.get(Calendar.YEAR) < 1900) // { // return BAD_DATE; // } // else // { // Because of daylight time saving we cannot use // date.getTime() - calStart.getTimeInMillis() // as the difference in milliseconds between 00:00 and 04:00 // can be 3, 4 or 5 hours but Excel expects it to always // be 4 hours. // E.g. 2004-03-28 04:00 CEST - 2004-03-28 00:00 CET is 3 hours // and 2004-10-31 04:00 CET - 2004-10-31 00:00 CEST is 5 hours final double fraction = (((calStart.get(Calendar.HOUR_OF_DAY) * 60 + calStart.get(Calendar.MINUTE)) * 60 + calStart.get(Calendar.SECOND)) * 1000 + calStart.get(Calendar.MILLISECOND)) / (double) DAY_MILLISECONDS; calStart = dayStart(calStart); return fraction + (double) absoluteDay(calStart) - CAL_1900_ABSOLUTE; }
From source file:com.esofthead.mycollab.core.utils.StringUtils.java
public static String generateSoftUniqueId() { return "" + (new GregorianCalendar().getTimeInMillis()) + new Random().nextInt(10); }