List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:net.sf.jasperreports.engine.util.JRDateLocaleConverter.java
/** * *//*from w w w . j a v a2s . c o m*/ private SimpleDateFormat getFormatter(String pattern, Locale locale) { if (pattern == null) { pattern = locPattern ? new SimpleDateFormat().toLocalizedPattern() : new SimpleDateFormat().toPattern(); log.warn("Null pattern was provided, defaulting to: " + pattern); } SimpleDateFormat format = new SimpleDateFormat(pattern, locale); if (timeZone != null) { format.setTimeZone(timeZone); } format.setLenient(isLenient()); return format; }
From source file:com.uber.hoodie.utilities.keygen.TimestampBasedKeyGenerator.java
@Override public HoodieKey getKey(GenericRecord record) { Object partitionVal = record.get(partitionPathField); SimpleDateFormat partitionPathFormat = new SimpleDateFormat(outputDateFormat); partitionPathFormat.setTimeZone(TimeZone.getTimeZone("GMT")); try {/* w ww. j av a 2 s . c o m*/ long unixTime; if (partitionVal instanceof Double) { unixTime = ((Double) partitionVal).longValue(); } else if (partitionVal instanceof Float) { unixTime = ((Float) partitionVal).longValue(); } else if (partitionVal instanceof Long) { unixTime = (Long) partitionVal; } else if (partitionVal instanceof String) { unixTime = inputDateFormat.parse(partitionVal.toString()).getTime() / 1000; } else { throw new HoodieNotSupportedException( "Unexpected type for partition field: " + partitionVal.getClass().getName()); } return new HoodieKey(record.get(recordKeyField).toString(), partitionPathFormat.format(new Date(unixTime * 1000))); } catch (ParseException pe) { throw new HoodieDeltaStreamerException("Unable to parse input partition field :" + partitionVal, pe); } }
From source file:eu.liveGov.libraries.livegovtoolkit.helper.LogFileHelper.java
public void postLogFile(Context con) { if (logFileLocation != null) { logger.info("postLogFile; prepaire to send log file"); File file = new File(logFileLocation); File tmpFile = new File(logFileLocation + ".tmp"); if (tmpFile.exists()) tmpFile.delete();//from ww w. j a va 2s . com try { copy(file, tmpFile); new FileOutputStream(file, false).close(); //creates an empty log file. TimeZone tz = TimeZone.getTimeZone("UTC"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); String nowAsISO = df.format(new Date()); logger.info("Starting new log file... ({})", nowAsISO); String json = "{\"filename\" : \"A_" + UserInformationHelper.getAnonymousUserId(con) + "_log.log\", \"enddate\" : \"" + nowAsISO + "\"}"; new DownloadHelper(this).postLogFile(tmpFile, json); } catch (IOException ioe) { logger.error("postLogFile; {}", ioe); try { tmpFile.delete(); } catch (Exception e) { } } } }
From source file:com.graphaware.importer.data.access.BaseDataReader.java
/** * Create a date format for date conversions. * * @return date format. By default, it is "dd/MM/yyyy" in GMT+1. Override for different format. *//*from w w w . j a v a2 s . c o m*/ protected SimpleDateFormat dateFormat() { SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); format.setTimeZone(TimeZone.getTimeZone("GMT+1")); return format; }
From source file:com.persistent.cloudninja.scheduler.TenantStorageBWGenerator.java
/** * Gets StorageBandwidthBatchEntity from database to process the logs * @return batchesToProcess : List of StorageBandwidthBatchEntity * @throws URISyntaxException/*from ww w. j a v a 2 s .co m*/ * @throws StorageException * @throws ParseException */ private List<StorageBandwidthBatchEntity> getLogsToProcess() throws URISyntaxException, StorageException, ParseException { Map<String, String> mapAnalyticsLogs = storageUtility.getStorageAnalyticsLogs(); StorageBandwidthBatchEntity batchEntity = null; List<StorageBandwidthBatchEntity> batchesToProcess = new ArrayList<StorageBandwidthBatchEntity>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = null; for (String blobURI : mapAnalyticsLogs.keySet()) { batchEntity = storageBandwidthBatchDao.getStorageBandwidthBatch(blobURI); date = dateFormat.parse(mapAnalyticsLogs.get(blobURI)); if (null == batchEntity) { batchEntity = new StorageBandwidthBatchEntity(); batchEntity.setLastLineProcessed(0); batchEntity.setLastUpdatedTime(date); batchEntity.setLogUri(blobURI); batchesToProcess.add(batchEntity); } else if (batchEntity.getLastUpdatedTime().getTime() != date.getTime()) { batchEntity.setLastUpdatedTime(date); batchesToProcess.add(batchEntity); } } return batchesToProcess; }
From source file:com.cloudbees.jenkins.plugins.bitbucket.client.events.BitbucketCloudPullRequestEvent.java
private long toDate(String dateStr) { if (StringUtils.isBlank(dateStr)) { return 0; }/* w ww.jav a2 s . co m*/ final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); dateParser.setTimeZone(TimeZone.getTimeZone("GMT")); try { return dateParser.parse(dateStr).getTime(); } catch (ParseException e) { return 0; } }
From source file:com.clustercontrol.calendar.model.YMD.java
/** * /*from ww w . java2 s. c om*/ * Long?YMD?? * @param date */ public YMD(Long date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); sdf.setTimeZone(HinemosTime.getTimeZone()); String strYMD = sdf.format(date); String[] str = strYMD.split("/"); this.year = Integer.parseInt(str[0]); this.month = Integer.parseInt(str[1]); this.day = Integer.parseInt(str[2]); }
From source file:net.mozq.picto.core.ProcessCore.java
private static ProcessDataStatus process(ProcessCondition processCondition, ProcessData processData, Function<ProcessData, ProcessDataStatus> overwriteConfirm) throws IOException { ProcessDataStatus status;/* w w w . j a v a 2 s .c o m*/ Path destParentPath = processData.getDestPath().getParent(); if (destParentPath != null) { Files.createDirectories(destParentPath); } if (processCondition.isCheckDigest() || (processCondition.isChangeExifDate() && processData.getBaseDate() != null) || processCondition.isRemveExifTagsGps() || processCondition.isRemveExifTagsAll()) { Path destTempPath = null; try { destTempPath = Files.createTempFile(processData.getDestPath().getParent(), processData.getDestPath().getFileName().toString(), null); if (processCondition.isCheckDigest()) { String algorithm = FILE_DIGEST_ALGORITHM; MessageDigest srcMD = newMessageDigest(algorithm); try (InputStream is = new DigestInputStream( new BufferedInputStream(Files.newInputStream(processData.getSrcPath())), srcMD)) { Files.copy(is, destTempPath, OPTIONS_COPY_REPLACE); } byte[] srcDigest = srcMD.digest(); MessageDigest destMD = newMessageDigest(algorithm); try (InputStream is = new DigestInputStream( new BufferedInputStream(Files.newInputStream(destTempPath)), destMD)) { byte[] b = new byte[1024]; while (is.read(b) != -1) { } } byte[] destDigest = destMD.digest(); if (!isSame(srcDigest, destDigest)) { throw new PictoFileDigestMismatchException( Messages.getString("message.error.digest.mismatch")); } } else if (processCondition.isRemveExifTagsAll()) { ExifRewriter exifRewriter = new ExifRewriter(); try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(destTempPath))) { exifRewriter.removeExifMetadata(processData.getSrcPath().toFile(), os); } catch (ImageReadException | ImageWriteException e) { throw new PictoFileChangeException(Messages.getString("message.error.edit.file"), e); } } else if (processCondition.isChangeExifDate() || processCondition.isRemveExifTagsGps()) { ImageMetadata imageMetadata = getImageMetadata(processData.getSrcPath()); TiffOutputSet outputSet = getOutputSet(imageMetadata); if (outputSet == null) { Files.copy(processData.getSrcPath(), destTempPath, OPTIONS_COPY_REPLACE); } else { if (processCondition.isChangeExifDate()) { SimpleDateFormat exifDateFormat = new SimpleDateFormat(EXIF_DATE_PATTERN); exifDateFormat.setTimeZone(processCondition.getTimeZone()); String exifBaseDate = exifDateFormat.format(processData.getBaseDate()); DecimalFormat exifSubsecFormat = new DecimalFormat(EXIF_SUBSEC_PATTERN); String exifBaseSubsec = exifSubsecFormat .format((int) (processData.getBaseDate().getTime() / 10) % 100); try { TiffOutputDirectory rootDirectory = outputSet.getRootDirectory(); TiffOutputDirectory exifDirectory = outputSet.getExifDirectory(); if (rootDirectory != null) { rootDirectory.removeField(TiffTagConstants.TIFF_TAG_DATE_TIME); rootDirectory.add(TiffTagConstants.TIFF_TAG_DATE_TIME, exifBaseDate); } if (exifDirectory != null) { exifDirectory.removeField(ExifTagConstants.EXIF_TAG_SUB_SEC_TIME); exifDirectory.add(ExifTagConstants.EXIF_TAG_SUB_SEC_TIME, exifBaseSubsec); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, exifBaseDate); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_SUB_SEC_TIME_ORIGINAL); exifDirectory.add(ExifTagConstants.EXIF_TAG_SUB_SEC_TIME_ORIGINAL, exifBaseSubsec); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED); exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED, exifBaseDate); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_SUB_SEC_TIME_DIGITIZED); exifDirectory.add(ExifTagConstants.EXIF_TAG_SUB_SEC_TIME_DIGITIZED, exifBaseSubsec); } } catch (ImageWriteException e) { throw new PictoFileChangeException(Messages.getString("message.error.edit.file"), e); } } if (processCondition.isRemveExifTagsGps()) { outputSet.removeField(ExifTagConstants.EXIF_TAG_GPSINFO); } ExifRewriter exifRewriter = new ExifRewriter(); try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(destTempPath))) { exifRewriter.updateExifMetadataLossless(processData.getSrcPath().toFile(), os, outputSet); } catch (ImageReadException | ImageWriteException e) { throw new PictoFileChangeException(Messages.getString("message.error.edit.file"), e); } } } Path destPath; if (processCondition.getOperationType() == OperationType.Overwrite) { destPath = processData.getSrcPath(); } else { destPath = processData.getDestPath(); } try { Files.move(destTempPath, destPath, OPTIONS_MOVE); if (processCondition.getOperationType() == OperationType.Move) { Files.deleteIfExists(processData.getSrcPath()); } status = ProcessDataStatus.Success; } catch (FileAlreadyExistsException e) { status = confirmOverwrite(processCondition, processData, overwriteConfirm); if (status == ProcessDataStatus.Processing) { // Overwrite Files.move(destTempPath, destPath, OPTIONS_MOVE_REPLACE); if (processCondition.getOperationType() == OperationType.Move) { Files.deleteIfExists(processData.getSrcPath()); } status = ProcessDataStatus.Success; } } } finally { if (destTempPath != null) { Files.deleteIfExists(destTempPath); } } } else { switch (processCondition.getOperationType()) { case Copy: try { Files.copy(processData.getSrcPath(), processData.getDestPath(), OPTIONS_COPY); status = ProcessDataStatus.Success; } catch (FileAlreadyExistsException e) { status = confirmOverwrite(processCondition, processData, overwriteConfirm); if (status == ProcessDataStatus.Processing) { Files.copy(processData.getSrcPath(), processData.getDestPath(), OPTIONS_COPY_REPLACE); status = ProcessDataStatus.Success; } } break; case Move: try { Files.move(processData.getSrcPath(), processData.getDestPath(), OPTIONS_MOVE); status = ProcessDataStatus.Success; } catch (FileAlreadyExistsException e) { status = confirmOverwrite(processCondition, processData, overwriteConfirm); if (status == ProcessDataStatus.Processing) { Files.move(processData.getSrcPath(), processData.getDestPath(), OPTIONS_MOVE_REPLACE); status = ProcessDataStatus.Success; } } break; case Overwrite: // NOP status = ProcessDataStatus.Success; break; default: throw new IllegalStateException(processCondition.getOperationType().toString()); } } if (status == ProcessDataStatus.Success) { FileTime creationFileTime = processData.getSrcFileAttributes().creationTime(); FileTime modifiedFileTime = processData.getSrcFileAttributes().lastModifiedTime(); FileTime accessFileTime = processData.getSrcFileAttributes().lastAccessTime(); if (processCondition.isChangeFileCreationDate() || processCondition.isChangeFileModifiedDate() || processCondition.isChangeFileAccessDate()) { if (processData.getBaseDate() != null) { FileTime baseFileTime = FileTime.fromMillis(processData.getBaseDate().getTime()); if (processCondition.isChangeFileCreationDate()) { creationFileTime = baseFileTime; } if (processCondition.isChangeFileModifiedDate()) { modifiedFileTime = baseFileTime; } if (processCondition.isChangeFileAccessDate()) { accessFileTime = baseFileTime; } } } BasicFileAttributeView attributeView = Files.getFileAttributeView(processData.getDestPath(), BasicFileAttributeView.class); attributeView.setTimes(modifiedFileTime, accessFileTime, creationFileTime); } return status; }
From source file:com.ichi2.libanki.Utils.java
/** * Returns the effective date of the present moment. * If the time is prior the cut-off time (9:00am by default as of 11/02/10) return yesterday, * otherwise today//w ww. j a v a 2 s. c o m * Note that the Date class is java.sql.Date whose constructor sets hours, minutes etc to zero * * @param utcOffset The UTC offset in seconds we are going to use to determine today or yesterday. * @return The date (with time set to 00:00:00) that corresponds to today in Anki terms */ public static Date genToday(double utcOffset) { // The result is not adjusted for timezone anymore, following libanki model // Timezone adjustment happens explicitly in Deck.updateCutoff(), but not in Deck.checkDailyStats() SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); df.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(System.currentTimeMillis() - (long) utcOffset * 1000l); return Date.valueOf(df.format(cal.getTime())); }