List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:org.openhab.persistence.dynamodb.internal.AbstractDynamoDBItemSerializationTest.java
@Test public void testDateTimeTypeLocalWithDateTimeItem() throws IOException { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT+03:00")); calendar.setTimeInMillis(1468773487050L); // GMT: Sun, 17 Jul 2016 16:38:07.050 GMT DynamoDBItem<?> dbitem = testStateGeneric(new DateTimeType(calendar), "2016-07-17T16:38:07.050Z"); // when deserializing data, we get the date in UTC Calendar Calendar expectedCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expectedCal.setTimeInMillis(1468773487050L); testAsHistoricGeneric(dbitem, new DateTimeItem("foo"), new DateTimeType(expectedCal)); }
From source file:org.sipfoundry.sipxconfig.admin.Whacker.java
/** * Convert the time-of-day string to a Date, expressed in GMT because that is what * DailyBackupSchedule is expecting.//from ww w .j a v a 2s .c o m */ private Date getTimeOfDayValue() { Calendar date = Calendar.getInstance(); date.set(Calendar.HOUR_OF_DAY, m_hours); date.set(Calendar.MINUTE, m_minutes); // switch to GMT timezone date.setTimeZone(TimeZone.getTimeZone("GMT")); return date.getTime(); }
From source file:RolloverFileOutputStream.java
public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone) throws IOException { super(null);/*from w w w . j ava 2 s . c o m*/ _fileBackupFormat.setTimeZone(zone); _fileDateFormat.setTimeZone(zone); if (filename != null) { filename = filename.trim(); if (filename.length() == 0) filename = null; } if (filename == null) throw new IllegalArgumentException("Invalid filename"); _filename = filename; _append = append; _retainDays = retainDays; setFile(); synchronized (RolloverFileOutputStream.class) { if (__rollover == null) __rollover = new Timer(); _rollTask = new RollTask(); Calendar now = Calendar.getInstance(); now.setTimeZone(zone); GregorianCalendar midnight = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), 23, 0); midnight.setTimeZone(zone); midnight.add(Calendar.HOUR, 1); __rollover.scheduleAtFixedRate(_rollTask, midnight.getTime(), 1000L * 60 * 60 * 24); } }
From source file:org.sakaiproject.component.section.sakai.CourseSectionImpl.java
/** * Check if converted time to the time zone of user is the previous day, * the same day or next day. //w w w .j a va 2 s . c o m * @param startTime denotes the time set by user (in his own TimeZone) * @return if converted from stored time zone to user time zone get the previous day returns -1 * if converted from stored time zone to user time zone get the same day returns 0 * if converted from stored time zone to user time zone get the next day returns +1 */ private static final int shiftDay(String str) { if (StringUtils.trimToNull(str) == null) { return 0; } try { SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_LONG); sdf.parse(str); return 0; } catch (Exception e) { // Stored in other format, with date and time zone. try { SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_DATE_TZ); Calendar src = new GregorianCalendar(); src.setTime(sdf.parse(str)); TimeZone srcTz = sdf.getTimeZone(); TimeZone userTz = timeService.getLocalTimeZone(); Calendar user = new GregorianCalendar(userTz); src.set(Calendar.DAY_OF_MONTH, user.get(Calendar.DAY_OF_MONTH)); src.set(Calendar.YEAR, user.get(Calendar.YEAR)); src.set(Calendar.MONTH, user.get(Calendar.MONTH)); user.setTimeInMillis(src.getTimeInMillis()); src.setTimeZone(srcTz); int shift = user.get(Calendar.DAY_OF_MONTH) - src.get(Calendar.DAY_OF_MONTH); // Days from two differents months if (shift > 8) { src.add(Calendar.MONTH, -1); shift -= src.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); } else if (shift < -8) { user.add(Calendar.MONTH, -1); shift += user.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); } return shift; } catch (Exception ex) { if (log.isDebugEnabled()) log.debug("Unable to parse " + str); return 0; } } }
From source file:com.chinamobile.bcbsp.fault.storage.MonitorFaultLog.java
/** * write fault log./*from www. java 2 s . c o m*/ * @param buffer * according fault time to create directory and write fault file */ protected void write(StringBuffer buffer) { Date now = new Date(System.currentTimeMillis()); timezone = TimeZone.getTimeZone("GMT+08:00"); Calendar currentTime = Calendar.getInstance(); currentTime.setTimeZone(timezone); currentTime.setTime(now); String dateText = null; String logFileName = "faultLog.txt"; String YEAR = String.valueOf(currentTime.get(Calendar.YEAR)); String MONTH = String.valueOf(currentTime.get(Calendar.MONTH) + 1); String DAY = String.valueOf(currentTime.get(Calendar.DAY_OF_MONTH)); dateText = YEAR + "/" + MONTH + "/" + DAY + "--"; storagePath = localDirPath + dateText + logFileName; write(buffer, storagePath); }
From source file:edu.missouri.bas.bluetooth.equivital.EquivitalRunnable.java
private void writeChestSensorDatatoCSV(String chestSensorData) { // TODO Auto-generated method stub //Toast.makeText(serviceContext,"Trying to write to the file",Toast.LENGTH_LONG).show(); Calendar c = Calendar.getInstance(); SimpleDateFormat curFormater = new SimpleDateFormat("MMMMM_dd"); String dateObj = curFormater.format(c.getTime()); String file_name = "chestsensor." + deviceName + "." + dateObj + ".txt"; Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("US/Central")); File f = new File(BASE_PATH, file_name); String dataToWrite = String.valueOf(cal.getTime()) + "," + chestSensorData; dataPoints.add(dataToWrite + ";"); if (dataPoints.size() == 57) { List<String> subList = dataPoints.subList(0, 56); String data = subList.toString(); String formattedData = data.replaceAll("[\\[\\]]", ""); //sendDatatoServer("chestsensor"+"."+phoneAddress+"."+deviceName+"."+dateObj,formattedData); TransmitData transmitData = new TransmitData(); transmitData.execute("chestsensor" + "." + phoneAddress + "." + deviceName + "." + dateObj, formattedData);//from w w w . j a va 2s .c om Log.d("Equivital", "Data Point Sent"); subList.clear(); subList = null; } if (f != null) { try { writeToFile(f, dataToWrite); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.orange.oidc.secproxy_service.Token.java
Calendar fromStringToDate(String s) { if (s != null && s.length() > 0) { try {// www. j a va 2 s . com long d = Long.parseLong(s); Calendar c = Calendar.getInstance(); c.setTimeInMillis(d * 1000); c.setTimeZone(TimeZone.getDefault()); return c; } catch (Exception e) { } } return null; }
From source file:com.aremaitch.codestock2010.datadownloader.DownloaderV2.java
private Calendar convertToCalendar(String dateString) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(Long.parseLong(dateString.substring(6, 19))); cal.setTimeZone(TimeZone.getTimeZone("GMT" + dateString.substring(19, 24))); return cal;/*from w w w .ja v a 2 s . c o m*/ }
From source file:com.orange.oidc.tim.service.TokensKeys.java
Calendar fromStringToDate(String s) { if (s != null && s.length() > 0) { try {//from w w w . j a v a 2s. c o m long d = Long.parseLong(s); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT")); c.setTimeInMillis(d * 1000); return c; } catch (Exception e) { } } return null; }
From source file:org.infoscoop.dao.LogDAO.java
public void deleteOldLog() { Calendar currentDay = Calendar.getInstance(); if (currentDay.get(Calendar.DAY_OF_YEAR) != logDeleteDay.get(Calendar.DAY_OF_YEAR)) { PropertiesDAO pdao = PropertiesDAO.newInstance(); Properties property = pdao.findProperty("logStoragePeriod"); int storagePeriod = 365; try {//from w w w.ja v a 2s.co m storagePeriod = Integer.parseInt(property.getValue()); } catch (NumberFormatException ex) { log.error("Invalid logStoragePeriod property.", ex); } if (storagePeriod > 0) { Calendar deleteDate = Calendar.getInstance(); deleteDate.setTimeZone(TimeZone.getTimeZone("UTC")); deleteDate.add(Calendar.DATE, -(storagePeriod)); String queryString = "delete Logs where Date < ?"; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd00"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String date = sdf.format(deleteDate.getTime()); super.getHibernateTemplate().bulkUpdate(queryString, date); } logDeleteDay = currentDay; } }