List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:com.joey.Fujikom.common.mapper.JsonMapper.java
public JsonMapper(Include include) { // ?/*from w w w. j ava 2 s. c o m*/ if (include != null) { this.setSerializationInclusion(include); } // ????????? this.enableSimple(); // JSONJava this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // ? this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(""); } }); // HTML? this.registerModule(new SimpleModule().addSerializer(String.class, new JsonSerializer<String>() { @Override public void serialize(String value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(StringEscapeUtils.unescapeHtml4(value)); } })); // this.setTimeZone(TimeZone.getDefault());//getTimeZone("GMT+8:00") }
From source file:com.ccoe.build.alerts.pfdash.PfDashJob.java
public void run(File file) { String[] location = ServiceConfig.get("pfdash.db.host").split(";"); List<String> locationList = Arrays.asList(location); int port = ServiceConfig.getInt("pfdash.db.port"); String dbname = ServiceConfig.get("pfdash.db.name"); DB db = null;/*from w w w.jav a 2 s .com*/ Date date = new Date(); Date currentStartTime = DateUtils.getUTCOneDayBack(date); Date currentEndTime = DateUtils.getUTCMidnightZero(date); Condition current = new Condition(); current.setStartDate(currentStartTime); current.setEndDate(currentEndTime); Date previousStartTime = DateUtils.getUTCOneWeekBack(currentStartTime); Date previousEndTime = DateUtils.getUTCOneWeekBack(currentEndTime); Condition previous = new Condition(); previous.setStartDate(previousStartTime); previous.setEndDate(previousEndTime); File parentDirectory = null; Time time = new Time(); TimeZone timeZone = TimeZone.getDefault(); TimeZone utcTimeZone = TimeZone.getTimeZone("UTC"); time.setQueryStart(DateUtils.getDateTimeString(currentStartTime, utcTimeZone)); time.setQueryEnd(DateUtils.getDateTimeString(currentEndTime, utcTimeZone)); boolean warning = false; EmailSender rlb = null; try { db = Connector.connectDB(locationList, port, dbname); db.slaveOk(); parentDirectory = new File(PfDashJob.class.getResource("/").toURI()); File xmlFile = new File(parentDirectory, "alert_kpi_threshold.xml"); if (!xmlFile.exists()) { throw new FileNotFoundException(); } Compare com = new Compare(xmlFile, db); AlertResult ar = com.judgeRules(current, previous); time.setSend(DateUtils.getDateTimeString(date, timeZone)); System.out.println("Email sentTime: " + date); rlb = new EmailSender(ar, time); for (SingleResult singleResult : ar.getResultlist()) { if (!"#CACACA".equals(singleResult.getColor())) { warning = true; } } rlb.sendMail(file, warning); } catch (Exception e) { e.printStackTrace(); String trace = ExceptionUtils.getStackTrace(e); rlb = new EmailSender(); rlb.sendMail(trace, warning); System.out.println("[INFO]: Fail to send pfDash alert email, and an exception email has been send. "); } }
From source file:DateCache.java
/** * Constructor. Make a DateCache that will use the given format */ public DateCache(String format) { _formatString = format; setTimeZone(TimeZone.getDefault()); }
From source file:com.aerospike.load.Utils.java
/** * Parse command line parameters./*from www . j av a 2s. co m*/ * @param cl Commandline arguments * @return Parameters * @throws Exception */ protected static Parameters parseParameters(CommandLine cl) { String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", null); String timeToLive = cl.getOptionValue("et", "-1"); int ttl = (Integer.parseInt(timeToLive)); String timeout = cl.getOptionValue("tt", "0"); int to = (Integer.parseInt(timeout)); //Get timezone offset //get user input for timeZone and check for valid ID if (cl.hasOption("T")) { if (!Utils.checkTimeZoneID(cl)) log.error("TimeZone given is not a valid ID"); } String timeZone = cl.getOptionValue("T", TimeZone.getDefault().getID()); TimeZone source = TimeZone.getTimeZone(timeZone); TimeZone local = TimeZone.getDefault(); long timeZoneOffset = local.getRawOffset() - source.getRawOffset(); String errorCount = cl.getOptionValue("ec", "0"); int abortErrorCount = Integer.parseInt(errorCount); String writeAction = cl.getOptionValue("wa", "UPDATE"); WritePolicy writePolicy = new WritePolicy(); writePolicy.recordExistsAction = RecordExistsAction.valueOf(writeAction.toUpperCase()); writePolicy.timeout = to; char delimiter = ','; boolean ignoreFirstLine = true; boolean verbose = false; if (cl.hasOption("v")) { verbose = true; } return new Parameters(host, port, namespace, set, ttl, Constants.CSV_FILE, delimiter, timeZoneOffset, ignoreFirstLine, verbose, abortErrorCount, writePolicy); }
From source file:com.nridge.core.base.std.DatUtl.java
/** * Returns the Julian day number that begins at noon of this day. * Positive year signifies A.D., negative year B.C. * Remember that the year after 1 B.C. was 1 A.D. * <code>/*from www.j a va2 s .c om*/ * System.out.println("Julian date for May 23, 1968 : " + toJulian(new Date())); * </code> * <p> * Reference: Numerical Recipes in C, 2nd ed., Cambridge University Press 1992 * </p> * @param aDate The date to convert. * @return The calculated Julian Day value. */ public static double toJulian(Date aDate) { int[] yearMonthDay = new int[3]; TimeZone timeZone = TimeZone.getDefault(); Calendar calendarInstance = Calendar.getInstance(timeZone); calendarInstance.setTime(aDate); yearMonthDay[0] = calendarInstance.get(Calendar.YEAR); yearMonthDay[1] = calendarInstance.get(Calendar.MONTH) + 1; yearMonthDay[2] = calendarInstance.get(Calendar.DAY_OF_MONTH); return toJulian(yearMonthDay); }
From source file:com.binomed.showtime.android.util.CineShowtimeRequestManage.java
public static NearResp searchTheatersOrMovies(Context context, Double latitude, Double longitude, String cityName, String movieName, String theaterId, int day, int start, String origin, String hourLocalized, String minutesLocalized) throws Exception { URLBuilder andShowtimeUriBuilder = new URLBuilder(CineShowTimeEncodingUtil.convertLocaleToEncoding()); andShowtimeUriBuilder.setProtocol(HttpParamsCst.BINOMED_APP_PROTOCOL); andShowtimeUriBuilder.setAdress(getAppEngineUrl(context)); andShowtimeUriBuilder.completePath(HttpParamsCst.BINOMED_APP_PATH); andShowtimeUriBuilder/*from w ww .jav a 2 s .c o m*/ .completePath(((movieName != null) && (movieName.length() > 0)) ? HttpParamsCst.MOVIE_GET_METHODE : HttpParamsCst.NEAR_GET_METHODE); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LANG, Locale.getDefault().getLanguage()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_OUTPUT, HttpParamsCst.VALUE_XML); // andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_ZIP, HttpParamsCst.VALUE_TRUE); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_IE, CineShowTimeEncodingUtil.getEncoding()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_OE, CineShowTimeEncodingUtil.getEncoding()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_CURENT_TIME, String.valueOf(Calendar.getInstance().getTimeInMillis())); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_TIME_ZONE, TimeZone.getDefault().getID()); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_HOUR_LOCALIZE, hourLocalized); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_MIN_LOCALIZE, minutesLocalized); if (theaterId != null) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_THEATER_ID // , theaterId); } if (day > 0) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_DAY // , String.valueOf(day)); } if (start > 0) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_START // , String.valueOf(start)); } String countryCode = Locale.getDefault().getCountry(); Geocoder geocoder = CineShowtimeFactory.getGeocoder(); Location originalPlace = null; if (geocoder != null) { if (cityName != null) { try { cityName = URLDecoder.decode(cityName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } List<Address> addressList = null; try { addressList = geocoder.getFromLocationName(cityName, 1); } catch (Exception e) { Log.e(TAG, "error Searching cityName :" + cityName, e); } if ((addressList != null) && !addressList.isEmpty()) { if (addressList.get(0).getLocality() != null) { cityName = addressList.get(0).getLocality(); } // if (addressList.get(0).getLocality() != null && // addressList.get(0).getPostalCode() != null) { // cityName += " " + addressList.get(0).getPostalCode(); // } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getCountryCode() != null)) { cityName += ", " + addressList.get(0).getCountryCode(); } originalPlace = new Location("GPS"); originalPlace.setLongitude(addressList.get(0).getLongitude()); originalPlace.setLatitude(addressList.get(0).getLatitude()); countryCode = addressList.get(0).getCountryCode(); } if (cityName != null) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } } if ((latitude != null) && (longitude != null) && ((latitude != 0) && (longitude != 0))) { List<Address> addressList = null; try { addressList = geocoder.getFromLocation(latitude, longitude, 1); } catch (Exception e) { Log.e(TAG, "error Searching latitude, longitude :" + latitude + "," + longitude, e); } if ((addressList != null) && !addressList.isEmpty()) { if (addressList.get(0).getLocality() != null) { cityName = addressList.get(0).getLocality(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getPostalCode() != null)) { cityName += " " + addressList.get(0).getPostalCode(); } if ((addressList.get(0).getLocality() != null) && (addressList.get(0).getCountryCode() != null)) { cityName += ", " + addressList.get(0).getCountryCode(); } originalPlace = new Location("GPS"); originalPlace.setLongitude(addressList.get(0).getLongitude()); originalPlace.setLatitude(addressList.get(0).getLatitude()); countryCode = addressList.get(0).getCountryCode(); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LAT // , AndShowtimeNumberFormat.getFormatGeoCoord().format(latitude)); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LONG// , AndShowtimeNumberFormat.getFormatGeoCoord().format(longitude)); if (cityName != null) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } } } else { if (cityName != null) { try { cityName = URLDecoder.decode(cityName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_PLACE, cityName); } if ((latitude != null) && (longitude != null) && ((latitude != 0) && (longitude != 0))) { andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LAT // , AndShowtimeNumberFormat.getFormatGeoCoord().format(latitude)); andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_LONG// , AndShowtimeNumberFormat.getFormatGeoCoord().format(longitude)); } } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_COUNTRY_CODE, countryCode); if (movieName != null) { try { movieName = URLDecoder.decode(movieName, CineShowTimeEncodingUtil.getEncoding()); } catch (Exception e) { Log.e(TAG, "error during decoding", e); } andShowtimeUriBuilder.addQueryParameter(HttpParamsCst.PARAM_MOVIE_NAME, movieName); } String uri = andShowtimeUriBuilder.toUri(); Log.i(TAG, "send request : " + uri); //$NON-NLS-1$ HttpGet getMethod = CineShowtimeFactory.getHttpGet(); getMethod.setURI(new URI(uri)); HttpResponse res = CineShowtimeFactory.getHttpClient().execute(getMethod); XMLReader reader = CineShowtimeFactory.getXmlReader(); ParserNearResultXml parser = CineShowtimeFactory.getParserNearResultXml(); reader.setContentHandler(parser); InputSource inputSource = CineShowtimeFactory.getInputSource(); // inputSource.setByteStream(new GZIPInputStream(res.getEntity().getContent())); inputSource.setByteStream(res.getEntity().getContent()); reader.parse(inputSource); NearResp resultBean = parser.getNearRespBean(); resultBean.setCityName(cityName); return resultBean; }
From source file:org.openmeetings.utils.math.TimezoneUtil.java
/** * Returns the timezone based on the user profile, if not return the * timezone from the server// w ww. ja va 2 s . c om * * @param user * @return */ public TimeZone getTimezoneByUser(Users user) { if (user != null && user.getOmTimeZone() != null) { TimeZone timeZone = TimeZone.getTimeZone(user.getOmTimeZone().getIcal()); if (timeZone != null) { return timeZone; } } // if user has not time zone get one from the server configuration Configuration conf = cfgManagement.getConfKey(3L, "default.timezone"); if (conf != null) { OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(conf.getConf_value()); TimeZone timeZoneByOmTimeZone = TimeZone.getTimeZone(omTimeZone.getIcal()); if (timeZoneByOmTimeZone != null) { return timeZoneByOmTimeZone; } } // If everything fails take the servers default one log.error( "There is no correct time zone set in the configuration of OpenMeetings for the key default.timezone or key is missing in table, using default locale!"); return TimeZone.getDefault(); }
From source file:dk.teachus.backend.testdatagenerator.DynamicDataImport.java
public void doImport() { TimeZone timeZone = TimeZone.getDefault(); DateMidnight startDate = new DateMidnight().minusYears(3).withMonthOfYear(1).withDayOfMonth(10); DateMidnight endDate = new DateMidnight().withMonthOfYear(12).withDayOfMonth(31); deleteExistingData();/*from w w w . ja v a 2 s. c om*/ createVersion(); createDefaultTimezone(timeZone); createAdmin(); int numberOfTeachers = 1; for (int i = 1; i <= numberOfTeachers; i++) { log.info("Creating teacher number " + i + " of " + numberOfTeachers); Teacher teacher = createTeacher(i); createTeacherAttribute(teacher); createPupils(teacher, i); createPeriods(teacher, startDate); createBookings(teacher, startDate, endDate); verify(teacher); } log.info("Done"); }
From source file:com.jaxzin.iraf.demo.GSDemo.java
private static XYDataset createData() { TimeSeriesCollection tsc = new TimeSeriesCollection(); GrowthSimulator sim = new StandardGrowthSimulator(); sim.setDomain(new GSDomainImpl()); // Locate the simulation start point sim.getDomain().setInitialInvestment(Quantity.<Money>valueOf("45000 USD")); // Setup the data about me sim.getDomain().setInitialAge(28);/*from w w w. ja va 2s. c o m*/ sim.getDomain().setRetirementAge(60); sim.getDomain().setLifespan(90); // Setup the data about my job sim.getDomain().setInitialSalary(Quantity.<Money>valueOf("95000 USD")); sim.getDomain().setBonus(Quantity.<Dimensionless>valueOf("14 %")); sim.getDomain().setRaise(Quantity.<Dimensionless>valueOf("5.5 %")); sim.getDomain().setPaychecksPerYear(1); // Setup the data about contributions to IRA sim.getDomain().setContribution(Quantity.<Dimensionless>valueOf("4 %")); sim.getDomain().setEmployerMatch(Quantity.<Dimensionless>valueOf("75 %")); // Setup data about the market sim.getDomain().setRor1(Quantity.<Dimensionless>valueOf("10 %")); sim.getDomain().setRor2(Quantity.<Dimensionless>valueOf("5 %")); sim.getDomain().setRiskFreeRate(Quantity.<Dimensionless>valueOf("3 %")); sim.getDomain().setAdjustForInflation(false); // Setup data about retirement sim.getDomain().setRetirementFactor(Quantity.<Dimensionless>valueOf("25 %")); java.util.List<Money> moneys = null; try { moneys = sim.simulate(); } catch (SimulationException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } TimeSeries ts = new TimeSeries("", Year.class); for (Money money : moneys) { if (ts.getItemCount() == 0) { ts.add(RegularTimePeriod.createInstance(Year.class, DateUtilities.createDate(2006, 1, 1), TimeZone.getDefault()), money.doubleValue()); } else { ts.add(ts.getNextTimePeriod(), money.doubleValue()); } } tsc.addSeries(ts); return tsc; }
From source file:com.adaptris.ftp.ApacheFtpClientImpl.java
/** * Constructor//from ww w . jav a 2 s . c o m * * @param remoteHost the remote hostname * @param port connection port * @param timeout connection timeout */ public ApacheFtpClientImpl(String remoteHost, int port, int timeout) throws IOException { this(); this.remoteHost = remoteHost; this.port = port; setTimeout(timeout); tzHandler = new TimezoneDateHandler(TimeZone.getDefault()); }