List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:Main.java
public static void main(String[] args) { Date d = new Date(); System.out.println(d);/*from w w w .j av a 2 s . co m*/ DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("Australia/Sydney")); System.out.println(df.format(d)); df.setTimeZone(TimeZone.getTimeZone("Europe/London")); System.out.println(df.format(d)); }
From source file:Main.java
public static void main(String[] args) throws Exception { String input = "Thu Jun 06 2015 00:00:00 GMT+0530 (India Standard Time)"; DateFormat inputFormat = new SimpleDateFormat("E MMM dd yyyy HH:mm:ss 'GMT'z", Locale.ENGLISH); Date date = inputFormat.parse(input); DateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH); outputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String output = outputFormat.format(date); System.out.println(output);//from ww w.ja v a 2s . com }
From source file:org.akvo.gae.remoteapi.CheckImages.java
public static void main(String[] args) { final String usr = args[0]; final String pwd = args[1]; final RemoteApiOptions options = new RemoteApiOptions().server("instance.appspot.com", 443).credentials(usr, pwd);// w ww . java2 s.c o m final RemoteApiInstaller installer = new RemoteApiInstaller(); File out = new File("/tmp/s3/qas.txt"); try { installer.install(options); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Filter f = new FilterPredicate("type", FilterOperator.EQUAL, "IMAGE"); Query q = new Query("QuestionAnswerStore").setFilter(f).addSort("createdDateTime", SortDirection.DESCENDING); PreparedQuery pq = ds.prepare(q); List<String> data = new ArrayList<String>(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); df.setTimeZone(TimeZone.getTimeZone("GMT")); for (Entity e : pq.asIterable(FetchOptions.Builder.withChunkSize(100))) { String val = (String) e.getProperty("value"); Date created = (Date) e.getProperty("createdDateTime"); int pos = val.lastIndexOf("/"); data.add(df.format(created) + "\t" + val.substring(pos + 1)); System.out.println("."); } System.out.println("Total:" + data.size()); System.out.println(data.subList(0, 10)); FileUtils.writeLines(out, data, "\n"); } catch (Exception e) { e.printStackTrace(); } finally { installer.uninstall(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String fromDateString = "Wed Jul 08 17:08:48 GMT 2015"; DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date fromDate = (Date) formatter.parse(fromDateString); TimeZone central = TimeZone.getTimeZone("America/Chicago"); formatter.setTimeZone(central); System.out.println(formatter.format(fromDate)); }
From source file:com.traffic.common.utils.http.HttpClientUtils.java
public static void main(String[] args) { //cst??GMT?/*from w ww .j av a 2 s.com*/ DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH); format.setTimeZone(TimeZone.getTimeZone("GMT")); String date = format.format(new Date()); String s = "license_plate_num=%E7%B2%A4BA804D&engine_num=C32764&body_num=064484&city_pinyin=shenzhen"; //?? String SIGNATURE = MD5Encrypt.encrypt("POST&/v3/violations&" + date + "&" + s.length() + "&" + MD5Encrypt.encrypt("uTIYrJn6vJTyt1ztBNbqQQDexDjpAM4m")); // headers.put("Host", "api.buding.cn"); headers.put("Authorization", "dLSQ1ZjK7exqlwqx:" + SIGNATURE); headers.put("Date", date); JSONObject reqParam = new JSONObject(); reqParam.put("license_plate_num", "BA804D"); reqParam.put("engine_num", "C32764"); reqParam.put("body_num", "064484"); reqParam.put("city_pinyin", "shenzhen"); String respBody = HttpClientUtils.httpPost_JSONObject("http://api.buding.cn/v3/violations", reqParam); System.out.println(JSONObject.parse(respBody)); }
From source file:Main.java
public static void main(String[] args) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00Z"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2015); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DATE, 1);//from w ww. j a v a 2s. c o m cal.set(Calendar.HOUR_OF_DAY, 12); cal.set(Calendar.MINUTE, 15); Date date = cal.getTime(); System.out.println(date); TimeZone tz = TimeZone.getTimeZone("IST"); dateFormat.setTimeZone(tz); String actual = dateFormat.format(date); System.out.println(actual); }
From source file:isi.pasco2.Main.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); Option undelete = new Option("d", "Undelete activity records"); options.addOption(undelete);/* w ww.j a v a 2s . c om*/ Option disableAllocation = new Option("M", "Disable allocation detection"); options.addOption(disableAllocation); Option fieldDelimeter = OptionBuilder.withArgName("field-delimeter").hasArg() .withDescription("Field Delimeter (TAB by default)").create("t"); options.addOption(fieldDelimeter); Option timeFormat = OptionBuilder.withArgName("time-format").hasArg() .withDescription("xsd or standard (pasco1 compatible)").create("f"); options.addOption(timeFormat); Option fileTypeOption = OptionBuilder.withArgName("file-type").hasArg() .withDescription("The type of file: cache or history").create("T"); options.addOption(fileTypeOption); try { CommandLine line = parser.parse(options, args); boolean undeleteMethod = false; String delimeter = null; String format = null; String fileType = null; boolean disableAllocationTest = false; if (line.hasOption("d")) { undeleteMethod = true; } if (line.hasOption('t')) { delimeter = line.getOptionValue('t'); } if (line.hasOption('M')) { disableAllocationTest = true; } if (line.hasOption('T')) { fileType = line.getOptionValue('T'); } if (line.hasOption('f')) { format = line.getOptionValue('f'); } if (line.getArgs().length != 1) { System.err.println("No file specified."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pasco2", options); System.exit(1); } String fileName = line.getArgs()[0]; try { IndexFile fr = new FastReadIndexFile(fileName, "r"); CountingCacheHandler handler = null; if (fileType == null) { handler = new CountingCacheHandler(); } if (fileType == null) { handler = new CountingCacheHandler(); } else if (fileType.equals("cache")) { handler = new CountingCacheHandler(); } else if (fileType.equals("history")) { handler = new Pasco2HistoryHandler(); } if (format != null) { if (format.equals("pasco")) { DateFormat regularDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"); handler.setDateFormat(regularDateFormat); TimeZone tz = TimeZone.getTimeZone("Australia/Brisbane"); regularDateFormat.setTimeZone(tz); } else if (format.equals("standard")) { DateFormat xsdDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); handler.setDateFormat(xsdDateFormat); xsdDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } else { System.err.println("Format not supported."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pasco2", options); System.exit(1); } } if (delimeter != null) { handler.setDelimeter(delimeter); } IEIndexFileParser logparser = null; if (fileType == null) { System.err.println("Using cache file parser."); logparser = new IECacheFileParser(fileName, fr, handler); } else if (fileType.equals("cache")) { logparser = new IECacheFileParser(fileName, fr, handler); } else if (fileType.equals("history")) { logparser = new IEHistoryFileParser(fileName, fr, handler); } else { System.err.println("Unsupported file type."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pasco2", options); System.exit(1); } if (disableAllocationTest) { logparser.setDisableAllocationTest(true); } logparser.parseFile(); } catch (Exception ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); } }
From source file:Main.java
private static final DateFormat parser(String format, TimeZone tz) { DateFormat out = parser(format); out.setTimeZone(tz); return out;/* ww w .j a v a2s . c o m*/ }
From source file:Main.java
public static String formatTime(long millisecond) { DateFormat format = new SimpleDateFormat("mm:ss"); format.setTimeZone(TimeZone.getTimeZone("GMT+00:00")); return format.format(millisecond); }
From source file:Main.java
private static final DateFormat formatter(String format, TimeZone tz) { DateFormat out = formatter(format); out.setTimeZone(tz); return out;// ww w. ja v a 2 s.c om }