List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:io.neba.core.logviewer.LogfileViewerConsolePlugin.java
/** * Prints the current server time and UTC offset, formatted using the servers time zone. *///from www. j a va 2s. c om private void serverTime(HttpServletResponse res) throws IOException { final long now = currentTimeMillis(); // Including current DST, if any. long utcOffsetInHours = TimeUnit.MILLISECONDS.toHours(TimeZone.getDefault().getOffset(now)); res.setContentType("application/json"); res.setCharacterEncoding("UTF-8"); res.setHeader("Cache-Control", "no-store"); res.getWriter().write('{'); res.getWriter().write("\"time\": \"" + DATETIME_FORMAT.format(currentTimeMillis()) + " (UTC " + (utcOffsetInHours < 0 ? "-" : "+") + " " + utcOffsetInHours + ")\""); res.getWriter().write('}'); }
From source file:au.com.ish.derbydump.derbydump.main.DumpTest.java
@Parameterized.Parameters(name = "{0}") public static Collection<Object[]> setupTestMatrix() throws Exception { List<Object[]> result = new ArrayList<Object[]>(); //testing numbers (BIGINT, DECIMAL, REAL, SMALLINT, INTEGER, DOUBLE) {//from w w w. j av a 2 s. c o m //standard set of numbers String[] columns = new String[] { "c1 BIGINT", "c2 DECIMAL(10,2)", "c3 REAL", "c4 SMALLINT", "c5 INTEGER", "c6 DOUBLE" }; Object[] row1 = new Object[] { new BigInteger("12"), new BigDecimal("12.12"), new Float("12.1"), Integer.valueOf(12), Integer.valueOf(24), Double.valueOf(12.12) }; String validOutput1 = "(12,12.12,12.1,12,24,12.12),"; Object[] row2 = new Object[] { new BigInteger("42"), new BigDecimal("42.12"), new Float("42.14"), Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42.14) }; String validOutput2 = "(42,42.12,42.14,42,64,42.14),"; Object[] row3 = new Object[] { new BigInteger("42"), new BigDecimal("42"), new Float("42"), Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42) }; String validOutput3 = "(42,42.00,42.0,42,64,42.0),"; Object[] row4 = new Object[] { new BigInteger("42"), new BigDecimal("42.1234"), new Float("42.1434"), Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42.1234) }; String validOutput4 = "(42,42.12,42.1434,42,64,42.1234),"; Object[] row5 = new Object[] { BigDecimal.ZERO, BigDecimal.ZERO, new Float("0"), Integer.valueOf(0), Integer.valueOf(0), Double.valueOf(0) }; String validOutput5 = "(0,0.00,0.0,0,0,0.0),"; //test nulls Object[] row6 = new Object[] { null, null, null, null, null, null }; String validOutput6 = "(NULL,NULL,NULL,NULL,NULL,NULL);"; Object[] values = new Object[] { row1, row2, row3, row4, row5, row6 }; String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3, validOutput4, validOutput5, validOutput6 }; result.add(new Object[] { "testNumbers", null, columns, values, validOutput, false, false }); } //testing strings { String[] columns = new String[] { "c1 VARCHAR(20)", "c2 VARCHAR(20)", "c3 VARCHAR(20)" }; //test normal characters Object[] row1 = new Object[] { "123", "abc", "" }; String validOutput1 = "('123','abc',''),"; //test nulls Object[] row2 = new Object[] { "%", null, "" }; String validOutput2 = "('%',NULL,''),"; //test quotes and tabs Object[] row3 = new Object[] { "'test'", "\"test\"", "\t" }; String validOutput3 = "('\\'test\\'','\"test\"','\\t'),"; //test new line chars Object[] row4 = new Object[] { "\n", "\r", "\n\r" }; String validOutput4 = "('\\n','\\r','\\n\\r');"; Object[] values = new Object[] { row1, row2, row3, row4 }; String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3, validOutput4 }; result.add(new Object[] { "testStrings", null, columns, values, validOutput, false, false }); } //testing dates { String[] columns = new String[] { "c1 TIMESTAMP", "c2 TIMESTAMP" }; // test standard dates Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.set(Calendar.YEAR, 2013); c.set(Calendar.MONTH, 5); c.set(Calendar.DAY_OF_MONTH, 6); c.set(Calendar.HOUR_OF_DAY, 11); c.set(Calendar.MINUTE, 10); c.set(Calendar.SECOND, 10); c.set(Calendar.MILLISECOND, 11); Calendar c2 = (Calendar) c.clone(); c2.add(Calendar.DATE, -5000); Object[] row1 = new Object[] { c.getTime(), c2.getTime() }; String validOutput1 = "('2013-06-06 11:10:10.011','1999-09-28 11:10:10.011'),"; Object[] row2 = new Object[] { "2012-07-07 08:54:33", "1999-09-09 10:04:10" }; String validOutput2 = "('2012-07-07 08:54:33.0','1999-09-09 10:04:10.0'),"; Object[] row3 = new Object[] { null, null }; String validOutput3 = "(NULL,NULL);"; Object[] values = new Object[] { row1, row2, row3 }; String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3 }; result.add(new Object[] { "testDates", null, columns, values, validOutput, false, false }); } //testing CLOB { String[] columns = new String[] { "c1 CLOB" }; Object[] row1 = new Object[] { "<clob value here>" }; String validOutput1 = "('<clob value here>'),"; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testClob", null, columns, values, validOutput, false, false }); } //testing BLOB { String[] columns = new String[] { "c1 BLOB" }; Object[] row1 = new Object[] { getTestImage() }; Blob serialBlob = new SerialBlob(IOUtils.toByteArray(getTestImage())); String validOutput1 = "(" + Column.processBinaryData(serialBlob) + "),"; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testBlob", null, columns, values, validOutput, false, false }); } //testing skipping table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] row1 = new Object[] { "123" }; String validOutput1 = ""; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testSkip", null, columns, values, validOutput, true, false }); } //testing renaming table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] row1 = new Object[] { "123" }; String validOutput1 = "('123'),"; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testRename", "testRenameNew", columns, values, validOutput, false, false }); } //testing empty table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] values = new Object[] { new Object[] {} }; String[] validOutput = new String[] {}; result.add(new Object[] { "testEmptyTable", null, columns, values, validOutput, true, false }); } //testing truncate table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] values = new Object[] { new Object[] {} }; String[] validOutput = new String[] {}; result.add(new Object[] { "testTruncateTable", null, columns, values, validOutput, true, true }); } return result; }
From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java
@Test public void testWrapperMethodsMexico() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("America/Mexico_City")); CelestialObject sun = new Sun(); Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.setTimeInMillis(0);/*from ww w .j a va 2s .com*/ c.set(Calendar.YEAR, 2009); c.set(Calendar.MONTH, Calendar.AUGUST); c.set(Calendar.DAY_OF_MONTH, 8); Date date = c.getTime(); Geolocation.Location location = new Geolocation.Location(); location.setLatitude(19.4328, Geolocation.Direction.NORTH); location.setLongitude(99.1333, Geolocation.Direction.WEST); TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL); logger.debug("Mexico"); logger.debug("Date : " + date); logger.debug("Julian : " + new JulianDate(date).julian()); logger.debug("Sunrise : Algorithms: " + details.getRiseTime() + " : " + details.getRiseTime().getTime()); logger.debug("Sunset : Algorithms: " + details.getSetTime() + " : " + details.getSetTime().getTime()); Assert.assertEquals(details.getRiseTime().getTime(), 1249732325341l, 1000); Assert.assertEquals(details.getSetTime().getTime(), 1249781509341l, 1000); }
From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPlugin.java
private String createTimestamp() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'_'HHmmss"); sdf.setTimeZone(TimeZone.getDefault()); String timestamp = sdf.format(new Date()); return timestamp; }
From source file:HardcopyWriter.java
/** * The constructor for this class has a bunch of arguments: The frame argument * is required for all printing in Java. The jobname appears left justified at * the top of each printed page. The font size is specified in points, as * on-screen font sizes are. The margins are specified in inches (or fractions * of inches).//from w w w . ja v a 2 s . c o m */ public HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin) throws HardcopyWriter.PrintCanceledException { // Get the PrintJob object with which we'll do all the printing. // The call is synchronized on the static printprops object, which // means that only one print dialog can be popped up at a time. // If the user clicks Cancel in the print dialog, throw an exception. Toolkit toolkit = frame.getToolkit(); // get Toolkit from Frame synchronized (printprops) { job = toolkit.getPrintJob(frame, jobname, printprops); } if (job == null) throw new PrintCanceledException("User cancelled print request"); pagesize = job.getPageDimension(); // query the page size pagedpi = job.getPageResolution(); // query the page resolution // Bug Workaround: // On windows, getPageDimension() and getPageResolution don't work, so // we've got to fake them. if (System.getProperty("os.name").regionMatches(true, 0, "windows", 0, 7)) { // Use screen dpi, which is what the PrintJob tries to emulate pagedpi = toolkit.getScreenResolution(); // Assume a 8.5" x 11" page size. A4 paper users must change this. pagesize = new Dimension((int) (8.5 * pagedpi), 11 * pagedpi); // We also have to adjust the fontsize. It is specified in points, // (1 point = 1/72 of an inch) but Windows measures it in pixels. fontsize = fontsize * pagedpi / 72; } // Compute coordinates of the upper-left corner of the page. // I.e. the coordinates of (leftmargin, topmargin). Also compute // the width and height inside of the margins. x0 = (int) (leftmargin * pagedpi); y0 = (int) (topmargin * pagedpi); width = pagesize.width - (int) ((leftmargin + rightmargin) * pagedpi); height = pagesize.height - (int) ((topmargin + bottommargin) * pagedpi); // Get body font and font size font = new Font("Monospaced", Font.PLAIN, fontsize); metrics = frame.getFontMetrics(font); lineheight = metrics.getHeight(); lineascent = metrics.getAscent(); charwidth = metrics.charWidth('0'); // Assumes a monospaced font! // Now compute columns and lines will fit inside the margins chars_per_line = width / charwidth; lines_per_page = height / lineheight; // Get header font information // And compute baseline of page header: 1/8" above the top margin headerfont = new Font("SansSerif", Font.ITALIC, fontsize); headermetrics = frame.getFontMetrics(headerfont); headery = y0 - (int) (0.125 * pagedpi) - headermetrics.getHeight() + headermetrics.getAscent(); // Compute the date/time string to display in the page header DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); df.setTimeZone(TimeZone.getDefault()); time = df.format(new Date()); this.jobname = jobname; // save name this.fontsize = fontsize; // save font size }
From source file:com.orange.oidc.secproxy_service.Token.java
Calendar fromStringToDate(String s) { if (s != null && s.length() > 0) { try {//w w w . j av a2 s . c o m 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:fr.inria.ucn.Helpers.java
/** * Collectors and Listeners should use this method to send the results to the service. * @param c/*ww w .j a v a 2 s .c om*/ * @param cid data collection id (maps to mongodb collection used to store the data) * @param ts periodic collection timestamp or event time if triggered by timestamp * @param data */ @SuppressLint("SimpleDateFormat") public static void sendResultObj(Context c, String cid, long ts, JSONObject data) { try { // wrap the collected data object to a common object format JSONObject res = new JSONObject(); // data collection in the backend db res.put("collection", cid); // store unique user id to each result object res.put("uid", getDeviceUuid(c)); // app version to help to detect data format changes try { PackageManager manager = c.getPackageManager(); PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0); res.put("app_version_name", info.versionName); res.put("app_version_code", info.versionCode); } catch (NameNotFoundException e) { } // event and current time in UTC JSON date format SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); res.put("ts_event", sdf.format(new Date(ts))); res.put("ts", sdf.format(new Date())); res.put("tz", TimeZone.getDefault().getID()); // devices current timezone res.put("tz_offset", TimeZone.getDefault().getOffset(ts)); // ts offset to this event // the data obj res.put("data", data); // ask the service to handle the data Intent intent = new Intent(c, CollectorService.class); intent.setAction(Constants.ACTION_DATA); intent.putExtra(Constants.INTENT_EXTRA_DATA, res.toString()); c.startService(intent); Log.d(Constants.LOGTAG, res.toString(4)); } catch (JSONException ex) { Log.w(Constants.LOGTAG, "failed to create json obj", ex); } }
From source file:com.bdb.weather.display.summary.WindSummary.java
/** * Load the data into the plot.//w w w . j ava2s . c o m * * @param records The summary records */ public void loadData(List<SummaryRecord> records) { dataTable.setItems(FXCollections.observableList(records)); TimeSeriesCollection sustainedDataset = new TimeSeriesCollection(); TimeSeries avgSpeedSeries = new TimeSeries("Average Sustained"); TimeSeries maxSpeedSeries = new TimeSeries("Maximum Sustained"); TimeSeriesCollection gustDataset = new TimeSeriesCollection(); TimeSeries windGustSeries = new TimeSeries("Maximum Gust"); for (int i = 0; i < records.size(); i++) { RegularTimePeriod p = RegularTimePeriod.createInstance(interval.getFreeChartClass(), TimeUtils.localDateTimeToDate(records.get(i).getDate().atStartOfDay()), TimeZone.getDefault()); maxSpeedSeries.add(p, records.get(i).getMaxWindSpeed().get()); avgSpeedSeries.add(p, records.get(i).getAvgWindSpeed().get()); Speed gust = records.get(i).getMaxWindGust(); if (gust != null) { windGustSeries.add(p, gust.get()); } } sustainedDataset.addSeries(avgSpeedSeries); sustainedDataset.addSeries(maxSpeedSeries); gustDataset.addSeries(windGustSeries); plot.setDataset(SUSTAINED_WIND_SERIES, sustainedDataset); plot.setDataset(GUST_SERIES, gustDataset); }
From source file:au.edu.uq.cmm.paul.servlet.WebUIController.java
@Override public void setServletContext(ServletContext servletContext) { LOG.debug("Setting the timezone (" + TimeZone.getDefault().getID() + ") in the servlet context"); servletContext.setAttribute("javax.servlet.jsp.jstl.fmt.timeZone", TimeZone.getDefault()); buildInfo = loadBuildInfo(servletContext); }
From source file:org.jfree.data.time.MillisecondTest.java
/** * Some checks for the getFirstMillisecond() method. *//*from www .j ava 2s . c om*/ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Millisecond m = new Millisecond(500, 15, 43, 15, 1, 4, 2006); assertEquals(1143902595500L, m.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }