List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:com.streamsets.pipeline.stage.bigquery.destination.BigQueryTarget.java
static SimpleDateFormat createSimpleDateFormat(String pattern) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat; }
From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java
public String toString(Object source) { XMLGregorianCalendar src = (XMLGregorianCalendar) source; SimpleDateFormat formatter = new SimpleDateFormat(DateConverter.DATE_FORMAT); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, src.getYear()); cal.set(Calendar.MONTH, src.getMonth() - 1); cal.set(Calendar.DAY_OF_MONTH, src.getDay()); cal.set(Calendar.HOUR, src.getHour()); cal.set(Calendar.MINUTE, src.getMinute()); cal.set(Calendar.SECOND, src.getSecond()); cal.set(Calendar.MILLISECOND, src.getMillisecond()); return formatter.format(cal.getTime()); }
From source file:co.uk.randompanda30.sao.modules.util.BackupUtil.java
public BackupUtil() { if (Config.ConfigValues.BACKUP_PATHTOBACKUP.value.toString().equalsIgnoreCase("changeme") || Config.ConfigValues.BACKUP_PATHTOSTORE.value.toString().equalsIgnoreCase("changeme") || Config.ConfigValues.BACKUP_TOSTORELOGS.value.toString().equalsIgnoreCase("changeme")) { // Some warning here return;//from ww w . j a v a 2 s . c o m } toBackup = Config.ConfigValues.BACKUP_PATHTOBACKUP.value + (Config.ConfigValues.BACKUP_PATHTOBACKUP.value.toString().endsWith("/") ? "" : "/"); toStore = Config.ConfigValues.BACKUP_PATHTOSTORE.value + (Config.ConfigValues.BACKUP_PATHTOSTORE.value.toString().endsWith("/") ? "" : "/"); toStoreLogs = Config.ConfigValues.BACKUP_TOSTORELOGS.value + (Config.ConfigValues.BACKUP_TOSTORELOGS.value.toString().endsWith("/") ? "" : "/"); SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy-HH:mm:ss-z"); f.setTimeZone(TimeZone.getTimeZone("Europe/London")); time = f.format(GregorianCalendar.getInstance().getTime()); if (!new File(toStore).exists()) { new File(toStore).mkdir(); } String time = (String) Config.ConfigValues.BACKUP_DELAY.value; String[] splitter = { time }; int days = 0; int hours = 0; int minutes = 0; int seconds = 0; if (!time.contains("d") && !time.contains("h") && !time.contains("m") && !time.contains("s")) { if (NumberUtil.isNumber(time)) { minutes = NumberUtil.getNumber(time); } else { time = "0"; } } else { if (time.contains("d")) { splitter = splitter[0].split("d"); days = NumberUtil.getNumber(splitter[0]); if (splitter.length == 2) { splitter[0] = splitter[1]; } } if (time.contains("h")) { splitter = splitter[0].split("h"); hours = NumberUtil.getNumber(splitter[0]); if (splitter.length == 2) { splitter[0] = splitter[1]; } } if (time.contains("m")) { splitter = splitter[0].split("m"); minutes = NumberUtil.getNumber(splitter[0]); if (splitter.length == 2) { splitter[0] = splitter[1]; } } if (time.contains("s")) { splitter = splitter[0].split("s"); seconds = NumberUtil.getNumber(splitter[0]); } if (time.equals("0")) { // Message here } delay = (days * 1000 * 60 * 60 * 24) + (hours * 1000 * 60 * 60) + (minutes * 1000 * 60) + (seconds * 1000); } if (!TEMP.backupc.contains("lastbackup")) { TEMP.backupc.set("lastbackup", System.currentTimeMillis()); CBackup.save(); backup(); } else { startTimer(); } }
From source file:org.springframework.batch.admin.domain.JobExecutionInfoResource.java
public JobExecutionInfoResource(JobExecution jobExecution, TimeZone timeZone) { if (timeZone != null) { this.timeZone = timeZone; } else {/*from w ww . j a va 2 s . c om*/ this.timeZone = TimeZone.getTimeZone("UTC"); } this.executionId = jobExecution.getId(); this.jobId = jobExecution.getJobId(); this.stepExecutionCount = jobExecution.getStepExecutions().size(); this.jobParameters = jobExecution.getJobParameters(); this.status = jobExecution.getStatus(); this.exitStatus = jobExecution.getExitStatus(); this.jobConfigurationName = jobExecution.getJobConfigurationName(); this.failureExceptions = jobExecution.getFailureExceptions(); Map<String, Object> executionContextEntires = new HashMap<String, Object>( jobExecution.getExecutionContext().size()); for (Map.Entry<String, Object> stringObjectEntry : jobExecution.getExecutionContext().entrySet()) { executionContextEntires.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); } this.executionContext = executionContextEntires; this.version = jobExecution.getVersion(); JobInstance jobInstance = jobExecution.getJobInstance(); if (jobInstance != null) { this.jobName = jobInstance.getJobName(); BatchStatus status = jobExecution.getStatus(); this.restartable = status.isGreaterThan(BatchStatus.STOPPING) && status.isLessThan(BatchStatus.ABANDONED); this.abandonable = status.isGreaterThan(BatchStatus.STARTED) && status != BatchStatus.ABANDONED; this.stoppable = status.isLessThan(BatchStatus.STOPPING) && status != BatchStatus.COMPLETED; } else { this.jobName = "?"; } this.dateFormat = this.dateFormat.withZone(DateTimeZone.forTimeZone(timeZone)); this.createDate = dateFormat.print(jobExecution.getCreateTime().getTime()); this.lastUpdated = dateFormat.print(jobExecution.getLastUpdated().getTime()); if (jobExecution.getStartTime() != null) { this.startTime = dateFormat.print(jobExecution.getStartTime().getTime()); this.endTime = dateFormat.print(jobExecution.getEndTime().getTime()); } }
From source file:com.uber.hoodie.utilities.keygen.TimestampBasedKeyGenerator.java
public TimestampBasedKeyGenerator(PropertiesConfiguration config) { super(config); UtilHelpers.checkRequiredProperties(config, Arrays.asList(Config.TIMESTAMP_TYPE_FIELD_PROP, Config.TIMESTAMP_OUTPUT_DATE_FORMAT_PROP)); this.timestampType = TimestampType.valueOf(config.getString(Config.TIMESTAMP_TYPE_FIELD_PROP)); this.outputDateFormat = config.getString(Config.TIMESTAMP_OUTPUT_DATE_FORMAT_PROP); if (timestampType == TimestampType.DATE_STRING || timestampType == TimestampType.MIXED) { UtilHelpers.checkRequiredProperties(config, Arrays.asList(Config.TIMESTAMP_INPUT_DATE_FORMAT_PROP)); this.inputDateFormat = new SimpleDateFormat(config.getString(Config.TIMESTAMP_INPUT_DATE_FORMAT_PROP)); this.inputDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); }/* w w w.j a v a 2s .co m*/ }
From source file:ISO8601DateParser.java
public static String toString(Date date) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); TimeZone tz = TimeZone.getTimeZone("UTC"); df.setTimeZone(tz);//from w ww . j a v a 2 s . c om String output = df.format(date); int inset0 = 9; int inset1 = 6; String s0 = output.substring(0, output.length() - inset0); String s1 = output.substring(output.length() - inset1, output.length()); String result = s0 + s1; result = result.replaceAll("UTC", "+00:00"); return result; }
From source file:com.jdo.CloudContactUtils.java
public static void main(String[] args) { // // ww w . j a v a2 s. c o m // List<CloudContactNotification> lc=new ArrayList<CloudContactNotification>(); // CloudContactNotification a=new CloudContactNotification(); // a.setLastAccess(""+new Date().getTime()); // a.setText("tt"); // a.setUserName("dhaneesh"); // lc.add(a); // // System.out.println(JSONObject.wrap(lc)); // try { //Asia/Calcutta String[] allTimeZones = TimeZone.getAvailableIDs(); Date now = new Date(); for (int i = 0; i < allTimeZones.length; i++) { //System.out.println(allTimeZones[i]); TimeZone tz = TimeZone.getTimeZone(allTimeZones[i]); System.out.format("%s;%s; %f \n", allTimeZones[i], tz.getDisplayName(), (float) (tz.getOffset(now.getTime()) / 3600000.0)); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.netflix.genie.client.BaseGenieClient.java
/** * Constructor that takes the service url and a security interceptor implementation. * * @param url The url of the Genie Service. * @param interceptors All desired interceptors for the client to be created * @param genieNetworkConfiguration A configuration object that provides network settings for HTTP calls. * @throws GenieClientException If there is any problem creating the constructor. *//*from w w w .ja va 2s. co m*/ public BaseGenieClient(@NotEmpty final String url, @Nullable final List<Interceptor> interceptors, @Nullable final GenieNetworkConfiguration genieNetworkConfiguration) throws GenieClientException { if (StringUtils.isBlank(url)) { throw new GenieClientException("Service URL cannot be empty or null"); } final OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (genieNetworkConfiguration != null) { this.addConfigParamsFromConfig(builder, genieNetworkConfiguration); } this.mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setDateFormat(new GenieDateFormat()).setTimeZone(TimeZone.getTimeZone("UTC")) .registerModule(new Jdk8Module()); // Add the interceptor to map the retrofit response code to corresponding Genie Exceptions in case of // 4xx and 5xx errors. builder.addInterceptor(new ResponseMappingInterceptor()); if (interceptors != null) { interceptors.forEach(builder::addInterceptor); } final OkHttpClient client = builder.build(); this.retrofit = new Retrofit.Builder().baseUrl(url) .addConverterFactory(JacksonConverterFactory.create(this.mapper)).client(client).build(); }
From source file:com.groupdocs.HomeController.java
@RequestMapping(value = "/view", method = RequestMethod.GET) public String index(Model model, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "fileId", required = false) String fileId, @RequestParam(value = "fileUrl", required = false) String fileUrl, @RequestParam(value = "filePath", required = false) String filePath, @RequestParam(value = "tokenId", required = false) String tokenId, @RequestParam(value = "userName", required = false) final String userName) throws Exception { if (annotationHandler == null) { TimeZone.setDefault(TimeZone.getTimeZone("Europe/Vilnius")); // Application path String appPath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); // File storage path String basePath = applicationConfig.getBasePath(); // File license path String licensePath = applicationConfig.getLicensePath(); // INITIALIZE GroupDocs Java Annotation Object ServiceConfiguration config = new ServiceConfiguration(appPath, basePath, licensePath, Boolean.FALSE, applicationConfig.getWidth()); annotationHandler = new AnnotationHandler(config); // InputDataHandler.setInputDataHandler(new CustomInputDataHandler(config)); }/*from w w w . j a v a2 s . c o m*/ // Setting header in jsp page model.addAttribute("groupdocsHeader", annotationHandler.getHeader()); // Initialization of Viewer with document from this path final GroupDocsPath groupDocsFilePath; if (fileId != null && !fileId.isEmpty()) { groupDocsFilePath = new FileId(fileId); } else if (filePath != null && !filePath.isEmpty()) { groupDocsFilePath = new FilePath(filePath, annotationHandler.getConfiguration()); } else if (fileUrl != null && !fileUrl.isEmpty()) { groupDocsFilePath = new FileUrl(fileUrl); } else if (tokenId != null && !tokenId.isEmpty()) { TokenId tki = new TokenId(tokenId); if (tki.isExpired()) { groupDocsFilePath = null; } else { groupDocsFilePath = tki; } } else { groupDocsFilePath = null; } final String userGuid = annotationHandler.addCollaborator(userName, groupDocsFilePath.getPath(), AccessRights.All, getIntFromColor(Color.black)); HashMap<String, String> params = new HashMap<String, String>() { { // You can skip parameters which have default value put("filePath", groupDocsFilePath.getPath()); // Default value: empty string put("width", Integer.toString(applicationConfig.getWidth())); // Default value: 800 put("height", Integer.toString(applicationConfig.getHeight())); // Default value: 600 put("quality", "75"); // Default value: 90 put("enableRightClickMenu", "true"); // Default value: true put("showHeader", Boolean.toString(applicationConfig.getShowHeader())); // Default value: true put("showZoom", Boolean.toString(applicationConfig.getShowZoom())); // Default value: true put("showPaging", Boolean.toString(applicationConfig.getShowPaging())); // Default value: true put("showPrint", Boolean.toString(applicationConfig.getShowPrint())); // Default value: false put("showFileExplorer", "true"); // Default value: true put("showThumbnails", Boolean.toString(applicationConfig.getShowThumbnails())); // Default value: true put("openThumbnails", Boolean.toString(applicationConfig.getOpenThumbnails())); // Default value: false put("zoomToFitWidth", "false"); // Default value: false put("zoomToFitHeight", "false"); // Default value: false put("initialZoom", "100"); // Default value: 100 put("preloadPagesCount", "0"); // Default value: 0 put("enableSidePanel", "true"); // Default value: true put("strikeOutColor", ""); // Default value: empty string put("enabledTools", "255"); // Default value: 255 put("saveReplyOnFocusLoss", "false"); // Default value: false put("strikeoutMode", "0"); // Default value: 0 put("sideboarContainerSelector", "div.comments_sidebar_wrapper"); // Default value: div.comments_sidebar_wrapper put("usePageNumberInUrlHash", "false"); // Default value: false put("textSelectionSynchronousCalculation", "true"); // Default value: true put("variableHeightPageSupport", "true"); // Default value: true put("useJavaScriptDocumentDescription", "true"); // Default value: true put("isRightPanelEnabled", "true"); // Default value: true put("createMarkup", "true"); // Default value: true put("use_pdf", "true"); // Default value: true put("_mode", "annotatedDocument"); // Default value: annotatedDocument put("selectionContainerSelector", "[name='selection-content']"); // Default value: [name='selection-content'] put("graphicsContainerSelector", ".annotationsContainer"); // Default value: .annotationsContainer put("widgetId", "annotation-widget"); // Default value: annotation-widget put("userName", userName == null ? "Anonimous" : userName); put("userGuid", userGuid); // put("showFolderBrowser", Boolean.toString(applicationConfig.getShowFolderBrowser())); // Not used // put("showDownload", Boolean.toString(applicationConfig.getShowDownload())); // Not used // put("showSearch", Boolean.toString(applicationConfig.getShowSearch())); // Not used } }; model.addAttribute("groupdocsScripts", annotationHandler.getScripts(params)); model.addAttribute("width", applicationConfig.getWidth()); // It is for sample JSP (index.jsp) model.addAttribute("height", applicationConfig.getHeight()); // It is for sample JSP (index.jsp) return "index"; }
From source file:com.mercandalli.android.apps.files.user.UserConversationMessageModel.java
public String getAdapterSubtitle() { String date = date_creation.toString(); SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC")); SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); try {/*from w w w . ja v a 2 s . c o m*/ date = TimeUtils.printDifferencePast(date_creation, dateFormatLocal.parse(dateFormatGmt.format(new Date()))); } catch (ParseException e) { Log.e(getClass().getName(), "Exception", e); } return getUsername() + " " + date + " ago"; }