List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:Spring.Repaso02.Principal.java
public static GregorianCalendar inicializaCal() { GregorianCalendar cal = new GregorianCalendar(); Date fecha = new Date(); cal.setTime(fecha); return cal;/* w w w . j a v a2s . c o m*/ }
From source file:com.autentia.common.util.DateFormater.java
public static Date normalizeInitDate(Date date) { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date); gCalendar.set(Calendar.HOUR_OF_DAY, 0); gCalendar.set(Calendar.MINUTE, 0); gCalendar.set(Calendar.SECOND, 0); gCalendar.set(Calendar.MILLISECOND, 0); return gCalendar.getTime(); }
From source file:com.autentia.common.util.DateFormater.java
public static Date normalizeEndDate(Date date) { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date); gCalendar.set(Calendar.HOUR_OF_DAY, 23); gCalendar.set(Calendar.MINUTE, 59); gCalendar.set(Calendar.SECOND, 59); gCalendar.set(Calendar.MILLISECOND, 999); return gCalendar.getTime(); }
From source file:TimeUtil.java
public static String dayStringFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(msecs)); int dow = cal.get(Calendar.DAY_OF_WEEK); switch (dow) { case Calendar.MONDAY: return "Monday"; case Calendar.TUESDAY: return "Tuesday"; case Calendar.WEDNESDAY: return "Wednesday"; case Calendar.THURSDAY: return "Thursday"; case Calendar.FRIDAY: return "Friday"; case Calendar.SATURDAY: return "Saturday"; case Calendar.SUNDAY: return "Sunday"; }/* ww w . java 2 s . c o m*/ return "Unknown"; }
From source file:TimeUtil.java
public static String windowFormat(long msecs) { Date tDate = new Date(msecs); long now = System.currentTimeMillis(); long diff = now - msecs; // start with the last 24 hours long comp = MS_PER_DAY; // start comparing if (diff < comp) { // it's within the last 24 hours - just return the time DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT); return formatter.format(tDate); }//from w w w .j a va 2 s . co m // now expand to another day comp += MS_PER_DAY; if (diff < comp) { // it's within the last 48 hours - just return the time DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT); return "Yesterday " + formatter.format(tDate); } // now up it to a week comp += 5 * MS_PER_DAY; if (diff < comp) { // return the day of the week and the time // get time to be formatted into a calendar GregorianCalendar tCal = new GregorianCalendar(); tCal.setTime(tDate); SimpleDateFormat formatter = new SimpleDateFormat("EEEE"); return formatter.format(tDate); } // just return full date DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return formatter.format(tDate); }
From source file:eu.impress.repository.util.EDXLlib.java
public static XMLGregorianCalendar getXMLGregorianCalendar() throws DatatypeConfigurationException { try {//from w w w .j a va 2s .co m Date now = new Date(); GregorianCalendar c = new GregorianCalendar(); c.setTime(now); XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); return date2; } catch (DatatypeConfigurationException c) { return null; } }
From source file:Main.java
public static XMLGregorianCalendar getXMLDate(final Date dateAndTime) { GregorianCalendar c = new GregorianCalendar(); c.setTimeZone(UTC);/*from w w w .j a v a 2 s. co m*/ c.setTime(dateAndTime); try { XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); return ret; } catch (DatatypeConfigurationException e) { return null; } }
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;//ww w .j a v a 2s . 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:com.erbjuder.logger.client.logmessage.util.LoggerToProxyObjects.java
public static XMLGregorianCalendar date2Gregorian(Date date) { DatatypeFactory dataTypeFactory; try {/*from w ww.j a v a2 s. c o m*/ dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("UTC")); gc.setTime(date); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:com.saax.gestorweb.util.DAOAleatorio.java
public static Date getDataByOffset(int offsetDataAtual, boolean up) { GregorianCalendar gc = new GregorianCalendar(); Date hoje = DateUtils.truncate(new Date(), Calendar.DATE); gc.setTime(hoje); // hoje truncando as horas for (int i = 0; i < offsetDataAtual; i++) { gc.roll(GregorianCalendar.DAY_OF_MONTH, up); if (gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) == gc.get(GregorianCalendar.DAY_OF_MONTH)) { gc.roll(GregorianCalendar.MONTH, up); }/* ww w . ja v a 2s.c om*/ } return DateUtils.truncate(new Date(gc.getTimeInMillis()), Calendar.DATE); }