List of usage examples for java.util Calendar getTimeZone
public TimeZone getTimeZone()
From source file:org.eclipse.ecr.core.storage.sql.jdbc.JDBCLogger.java
/** * Returns a loggable value using pseudo-SQL syntax. */// ww w. j a v a 2 s . c o m @SuppressWarnings("boxing") public static String loggedValue(Serializable value) { if (value == null) { return "NULL"; } if (value instanceof String) { String v = (String) value; if (v.length() > DEBUG_MAX_STRING) { v = v.substring(0, DEBUG_MAX_STRING) + "...(" + v.length() + " chars)..."; } return "'" + v.replace("'", "''") + "'"; } if (value instanceof Calendar) { Calendar cal = (Calendar) value; char sign; int offset = cal.getTimeZone().getOffset(cal.getTimeInMillis()) / 60000; if (offset < 0) { offset = -offset; sign = '-'; } else { sign = '+'; } return String.format("TIMESTAMP '%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d'", cal.get(Calendar.YEAR), // cal.get(Calendar.MONTH) + 1, // cal.get(Calendar.DAY_OF_MONTH), // cal.get(Calendar.HOUR_OF_DAY), // cal.get(Calendar.MINUTE), // cal.get(Calendar.SECOND), // cal.get(Calendar.MILLISECOND), // sign, offset / 60, offset % 60); } if (value instanceof Binary) { return "'" + ((Binary) value).getDigest() + "'"; } if (value.getClass().isArray()) { Serializable[] v = (Serializable[]) value; StringBuilder b = new StringBuilder(); b.append('['); for (int i = 0; i < v.length; i++) { if (i > 0) { b.append(','); if (i > DEBUG_MAX_ARRAY) { b.append("...(" + v.length + " items)..."); break; } } b.append(loggedValue(v[i])); } b.append(']'); return b.toString(); } return value.toString(); }
From source file:helper.util.DateHelper.java
/** * Take a local time calendar and represent it as a day * (truncate to day, retain yy/mm/dd from original date) **///from w w w. ja v a2 s . c o m public static Calendar asDay(Calendar localTimeCalendar) { Calendar asDay = Calendar.getInstance(localTimeCalendar.getTimeZone()); asDay.clear(); asDay.set(localTimeCalendar.get(Calendar.YEAR), localTimeCalendar.get(Calendar.MONTH), localTimeCalendar.get(Calendar.DATE), 0, 0, 0); asDay.set(Calendar.AM_PM, Calendar.AM); asDay.set(Calendar.MILLISECOND, 0); asDay.set(Calendar.HOUR, 0); return asDay; }
From source file:org.jasig.schedassist.model.CommonDateOperations.java
/** * Returns the approximate difference in DAYS between start and end. * //from w ww . j av a 2 s. com * @param start * @param end * @return the approximate number of days between the 2 dates */ public static long approximateDifference(Date start, Date end) { Calendar s = Calendar.getInstance(); s.setTime(start); Calendar e = Calendar.getInstance(); e.setTime(end); long endL = e.getTimeInMillis() + e.getTimeZone().getOffset(e.getTimeInMillis()); long startL = s.getTimeInMillis() + s.getTimeZone().getOffset(s.getTimeInMillis()); return (endL - startL) / MILLISECS_PER_DAY; }
From source file:es.tekniker.framework.ktek.util.Utils.java
private static long getTimeinMillis4FullDateTimeUTC(int year, int month, int day, int hours, int minutes, int seconds) { Calendar c = Calendar.getInstance(); System.out.println("current: " + c.getTime()); TimeZone z = c.getTimeZone(); int offset = z.getRawOffset(); if (z.inDaylightTime(new Date())) { offset = offset + z.getDSTSavings(); }/*from w w w. j a v a 2s . co m*/ int offsetHrs = offset / 1000 / 60 / 60; int offsetMins = offset / 1000 / 60 % 60; System.out.println("offsetHrs: " + offsetHrs); System.out.println("offsetMin: " + offsetMins); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month); c.set(Calendar.DAY_OF_MONTH, day); c.set(Calendar.HOUR_OF_DAY, (hours - offsetHrs)); c.set(Calendar.MINUTE, (minutes - offsetMins)); c.set(Calendar.SECOND, seconds); System.out.println("GMT Time: " + c.getTime()); long timeinmillis = c.getTimeInMillis(); System.out.println(" system time in millis " + timeinmillis); return timeinmillis; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger.java
/** * Returns a loggable value using pseudo-SQL syntax. *//*from w w w . j ava2 s . c o m*/ @SuppressWarnings("boxing") public static String loggedValue(Object value) { if (value == null) { return "NULL"; } if (value instanceof String) { String v = (String) value; if (v.length() > DEBUG_MAX_STRING) { v = v.substring(0, DEBUG_MAX_STRING) + "...(" + v.length() + " chars)..."; } return "'" + v.replace("'", "''") + "'"; } if (value instanceof Calendar) { Calendar cal = (Calendar) value; char sign; int offset = cal.getTimeZone().getOffset(cal.getTimeInMillis()) / 60000; if (offset < 0) { offset = -offset; sign = '-'; } else { sign = '+'; } return String.format("TIMESTAMP '%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d'", cal.get(Calendar.YEAR), // cal.get(Calendar.MONTH) + 1, // cal.get(Calendar.DAY_OF_MONTH), // cal.get(Calendar.HOUR_OF_DAY), // cal.get(Calendar.MINUTE), // cal.get(Calendar.SECOND), // cal.get(Calendar.MILLISECOND), // sign, offset / 60, offset % 60); } if (value instanceof java.sql.Date) { return "DATE '" + value.toString() + "'"; } if (value instanceof Binary) { return "'" + ((Binary) value).getDigest() + "'"; } if (value instanceof Object[]) { Object[] v = (Object[]) value; StringBuilder b = new StringBuilder(); b.append('['); for (int i = 0; i < v.length; i++) { if (i > 0) { b.append(','); if (i > DEBUG_MAX_ARRAY) { b.append("...(" + v.length + " items)..."); break; } } b.append(loggedValue(v[i])); } b.append(']'); return b.toString(); } return value.toString(); }
From source file:org.jrecruiter.common.CalendarUtils.java
/** * Get a XML-date representation (ISO 8601) of the provided calendar object. * * For more details @see http://www.w3.org/TR/xmlschema-2/#dateTime * * @return XML-date as String/*w w w.java2 s. c o m*/ */ public static String getXmlFormatedDate(final Calendar calendar) { if (calendar == null) { throw new IllegalArgumentException("Calendar is a required parameter"); } final GregorianCalendar gregorianCalendar = new GregorianCalendar(calendar.getTimeZone()); gregorianCalendar.setTime(calendar.getTime()); final DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } final XMLGregorianCalendar xmlCalendar = dataTypeFactory.newXMLGregorianCalendar(gregorianCalendar); return xmlCalendar.toXMLFormat(); }
From source file:org.apache.accumulo.monitor.servlets.DefaultServlet.java
/** * Converts a unix timestamp in UTC to one that is relative to the local timezone *//*from w w w .j a v a 2s .c o m*/ private static Long utc2local(Long utcMillis) { Calendar currentCalendar = Calendar.getInstance(); // default timezone currentCalendar.setTimeInMillis(utcMillis + currentCalendar.getTimeZone().getOffset(utcMillis)); return currentCalendar.getTime().getTime(); }
From source file:com.hurence.logisland.utils.DateUtils.java
public static String outputDateInfo(Date d) { String output = ""; Calendar c = GregorianCalendar.getInstance(tz); c.setTimeInMillis(d.getTime());// w w w . jav a 2 s .c o m TimeZone tzCal = c.getTimeZone(); output += "Date: " + d + "\n"; // toString uses current system TimeZone output += "Date Millis: " + d.getTime() + "\n"; output += "Cal Millis: " + c.getTimeInMillis() + "\n"; output += "Cal To Date Millis: " + c.getTime().getTime() + "\n"; output += "Cal TimeZone Name: " + tzCal.getDisplayName() + "\n"; output += "Cal TimeZone ID: " + tzCal.getID() + "\n"; output += "Cal TimeZone DST Name: " + tzCal.getDisplayName(true, TimeZone.SHORT) + "\n"; output += "Cal TimeZone Standard Name: " + tzCal.getDisplayName(false, TimeZone.SHORT) + "\n"; output += "In DayLight: " + tzCal.inDaylightTime(d) + "\n"; output += "" + "\n"; output += "Day Of Month: " + c.get(Calendar.DAY_OF_MONTH) + "\n"; output += "Month Of Year: " + c.get(Calendar.MONTH) + "\n"; output += "Year: " + c.get(Calendar.YEAR) + "\n"; output += "Hour Of Day: " + c.get(Calendar.HOUR_OF_DAY) + "\n"; output += "Minute: " + c.get(Calendar.MINUTE) + "\n"; output += "Second: " + c.get(Calendar.SECOND) + "\n"; return output; }
From source file:at.newsagg.utils.ParserUtils.java
private static Date extractTimeZone(String strdate, Date thedate) { // try to extract -06:00 String tzSign = strdate.substring(strdate.length() - 6, strdate.length() - 5); String tzHour = strdate.substring(strdate.length() - 5, strdate.length() - 3); String tzMin = strdate.substring(strdate.length() - 2); if (tzSign.equals("-") || tzSign.equals("+")) { int h = Integer.parseInt(tzHour); int m = Integer.parseInt(tzMin); // NOTE: this is really plus, since perspective is from GMT if (tzSign.equals("+")) { h = -1 * h;/*from ww w . j a v a 2 s. c o m*/ m = -1 * m; } Calendar cal = Calendar.getInstance(); cal.setTime(thedate); cal.add(Calendar.HOUR_OF_DAY, h); cal.add(Calendar.MINUTE, m); // calculate according the used timezone cal.add(Calendar.MILLISECOND, localTimeDiff(cal.getTimeZone(), thedate)); thedate = cal.getTime(); } return thedate; }
From source file:org.apache.nifi.registry.web.security.authentication.jwt.JwtService.java
private static String describe(AuthenticationResponse authenticationResponse) { Calendar expirationTime = Calendar.getInstance(); expirationTime.setTimeInMillis(authenticationResponse.getExpiration()); long remainingTime = expirationTime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS"); dateFormat.setTimeZone(expirationTime.getTimeZone()); String expirationTimeString = dateFormat.format(expirationTime.getTime()); return new StringBuilder("LoginAuthenticationToken for ").append(authenticationResponse.getUsername()) .append(" issued by ").append(authenticationResponse.getIssuer()).append(" expiring at ") .append(expirationTimeString).append(" [").append(authenticationResponse.getExpiration()) .append(" ms, ").append(remainingTime).append(" ms remaining]").toString(); }