List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
@Override public Date sunset(final Coordinate coordinate, final Date date) { final Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(date);// w w w. j a va 2s. co m final int day = calendar.get(Calendar.DAY_OF_YEAR); final double total = length(coordinate.getLatitude(), day); final int hours = (int) total; final int minutes = (int) ((((double) total) - ((double) hours)) * 60d); calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.HOUR_OF_DAY, hours / 2); calendar.add(Calendar.MINUTE, minutes / 2); calendar.add(Calendar.MINUTE, (int) localSolarTime(day)); final TimeZone timeZone = TimeZone.getDefault(); if (timeZone.inDaylightTime(date)) { calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings()); } return calendar.getTime(); }
From source file:com.opendesign.utils.Day.java
private void createDateFactorsByGivenMilliSecond(long milliSeconds, TimeZone timeZone) { if (timeZone == null) { this.timeZone = TimeZone.getDefault(); } else {/* w ww . ja v a 2s.c o m*/ this.timeZone = timeZone; } GregorianCalendar todaysDate = new GregorianCalendar(this.timeZone); if (milliSeconds != 0) { todaysDate.setTimeInMillis(milliSeconds); } this.year = todaysDate.get(Calendar.YEAR); this.month = todaysDate.get(Calendar.MONTH) + 1; this.day = todaysDate.get(Calendar.DAY_OF_MONTH); this.hour = todaysDate.get(Calendar.HOUR_OF_DAY); this.minute = todaysDate.get(Calendar.MINUTE); this.second = todaysDate.get(Calendar.SECOND); }
From source file:com.ykun.commons.utils.commons.DateUtils.java
/** * @param date//from w ww . j a va 2 s. c o m * @return * @throws * @Description:yyyy-MM-dd HH:mm:ss??Date */ public static Date stringToDate(String date) { return stringToDate(date, YYYY_MM_DD_HH_MM_SS, TimeZone.getDefault()); }
From source file:com.zhangyue.zeus.controller.TaskController.java
/** * ??/* w w w . ja va 2 s. c o m*/ * * @param query * @param name * @return */ @RequestMapping(value = "submit") public ModelAndView submitTask(@RequestParam(value = "query", required = false) String query, @RequestParam(value = "name", required = false) String name) { int userId = getUserId(); int level = getLevle(); // ?? if (null == name || name.equals(Constants.BLANK)) { Date created = Calendar.getInstance(TimeZone.getDefault()).getTime(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss"); name = sf.format(created); } request.setAttribute("name", name); request.setAttribute("query", query); // ??-?- HiveTableEntity hiveTableParam = new HiveTableEntity(); hiveTableParam.setUserId(userId); hiveTableParam.setLevel(level); hiveTableService.setHiveTableEntity(hiveTableParam); List<HiveTableEntity> tableList = hiveTableService.findHiveTableList(); request.setAttribute("tableList", tableList); String uri = "/query/create"; // ????5 QueriesEntity queriesEntity = new QueriesEntity(); queriesEntity.setUserId(userId); queriesEntity.setStatus(QueriesEntity.RunningStatus.RUNNING.getTypeName()); taskManageService.setQuery(queriesEntity); long count = taskManageService.findSubmitTaskCount(); if (count >= Constants.SUBMIT_COUNT) { request.setAttribute("msg", "5???????"); return new ModelAndView(uri); } // ??,???? if (level == 2) { CheckResult result = authorityManageService.checkPermission(userId, query); if (result.isResult()) { request.setAttribute("msg", result.getMsg()); return new ModelAndView(uri); } } LOG.debug("MQuery userId " + userId); QueriesEntity queriesEntity2 = new QueriesEntity(name, query, userId); taskManageService.setQuery(queriesEntity2); taskManageService.addQueryTask(); QueryManager.getInstance().submit(queriesEntity2); LOG.info("task name :" + queriesEntity2.getTaskName() + " query sql name: " + queriesEntity2.getQuerySql()); if (queriesEntity2 == null || queriesEntity2.getId() == 0) { request.setAttribute("msg", "save query failed"); return new ModelAndView(uri); } return new ModelAndView(new RedirectView(String.valueOf(queriesEntity2.getId()))); }
From source file:com.jdom.get.stuff.done.domain.Task.java
public boolean equals(com.google.api.services.tasks.model.Task googleTask, String listName) { EqualsBuilder eqBuilder = new EqualsBuilder(); eqBuilder.append(this.isDeleted(), Boolean.parseBoolean("" + googleTask.getDeleted())); eqBuilder.append(this.isCompleted(), "completed".equals(googleTask.getStatus())); eqBuilder.append(this.getName(), googleTask.getTitle()); eqBuilder.append(this.getListName(), listName); Date thisDueDate = DateUtil.getDateZeroingHoursAndBelow(getDueDate()); long raw = 0; DateTime googleDue = googleTask.getDue(); if (googleDue != null) { raw = googleDue.getValue();//from w w w . j av a2 s . com raw -= TimeZone.getDefault().getOffset(raw); } Date thatDueDate = DateUtil.getDateZeroingHoursAndBelow(new Date(raw)); eqBuilder.append(thisDueDate, thatDueDate); return eqBuilder.isEquals(); }
From source file:org.wikipedia.nirvana.nirvanabot.ReportItem.java
public String toStringTXT() { String line = ""; String timeString = "N/A"; if (timeDiff > 0) { timeString = String.format("%1$tT", timeDiff - TimeZone.getDefault().getRawOffset()); }/* ww w . j a v a 2s. c o m*/ String name2 = portal; String name1 = ""; if (name2.length() > MAX_LEN) { //int separator = max; int n = name2.lastIndexOf(' ', MAX_LEN); if (n < MAX_LEN - 20 || n < 0) { n = MAX_LEN; } name1 = name2.substring(0, n); name2 = name2.substring(n + 1); } String upd = this.updated ? NirvanaBot.YES : NirvanaBot.NO; String arch = this.archived ? NirvanaBot.YES : NirvanaBot.NO; line = String.format("%1$-90s %2$-9s %3$9s %4$3d %5$-3s %6$3d %7$-3s %8$2d %9$-13s", name2, status, timeString, this.newPagesFound, upd, this.pagesArchived, arch, this.errors, this.error.toString()); if (!name1.isEmpty()) { line = name1 + "\r\n" + line; } return line; }
From source file:com.icesoft.tutorial.TimeZoneBean.java
/** * Initializes this TimeZoneBean's properties. *///w w w .jav a 2 s. co m private void init() { serverTimeZone = TimeZone.getDefault(); serverFormat = buildDateFormatForTimeZone(serverTimeZone); selectedTimeZone = TimeZone.getTimeZone("Etc/GMT+0"); // selected time zone set to UTC as default selectedFormat = buildDateFormatForTimeZone(selectedTimeZone); // Entries in this list determine what will be generated in // the timezone web file, so should be modifiable, // but all ids must be unique to each other allTimeZoneList = new ArrayList(7); allTimeZoneList.add(new TimeZoneWrapper("Pacific/Honolulu", "GMTminus10", "HADT", hawaiiXCoords, hawaiiYCoords, hawaiiXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Anchorage", "GMTminus9", "AKST", alaskaXCoords, alaskaYCoords, alaskaXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Los_Angeles", "GMTminus8", "PST", pacificXCoords, pacificYCoords, pacificXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Denver", "GMTminus7", "MDT", mountainXCoords, mountainYCoords, mountainXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Chicago", "GMTminus6", "CDT", centralXCoords, centralYCoords, centralXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/New_York", "GMTminus5", "EST", easternXCoords, easternYCoords, easternXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("Canada/Newfoundland", "GMTminus4", "NST", nfldXCoords, nfldYCoords, nfldXCoords.length)); checkedTimeZoneList = new ArrayList(); state = PersistentFacesState.getInstance(); }
From source file:se.vgregion.services.calendar.CalendarServiceImpl.java
@Override public CalendarEvents getCalendarEventsFromIcalUrl(String url, CalendarEventsPeriod period, String type) throws CalendarServiceException { CalendarEvents calendarEvents = new CalendarEvents(); calendarEvents.setCalendarItems(new ArrayList<CalendarItem>()); Interval queryInterval = new Interval(period.getStartDate(), period.getEndDate()); try {/*from w ww . java2 s . co m*/ Calendar calendar = parseIcalUrl(url); Iterator<VEvent> itr = calendar.getComponents(Component.VEVENT).iterator(); while (itr.hasNext()) { VEvent vEvent = itr.next(); Date startDate = vEvent.getStartDate().getDate(); Date endDate = vEvent.getEndDate().getDate(); boolean wholeDays = !(startDate instanceof net.fortuna.ical4j.model.DateTime); if (wholeDays) { // Whole day event. Have had timezone problems with whole day events. Workaround it. String datePartStart = startDate.toString(); String datePartEnd = endDate.toString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); sdf.setTimeZone(TimeZone.getDefault()); try { java.util.Date startParsed = sdf.parse(datePartStart); java.util.Date endParsed = sdf.parse(datePartEnd); startDate = new net.fortuna.ical4j.model.DateTime(startParsed); // Subtract a millisecond so we don't regard the event as taking place on the next day. Now we // end the event one millisecond before the day turns. endDate = new net.fortuna.ical4j.model.DateTime(endParsed.getTime() - 1); } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } } Interval interval = new Interval(startDate.getTime(), endDate.getTime()); if (interval.overlaps(queryInterval)) { CalendarItem item = new CalendarItem(); item.setInterval(interval); item.setTitle(vEvent.getSummary().getValue()); item.setCalendarType(type); item.setWholeDays(wholeDays); calendarEvents.getCalendarItems().add(item); } } } catch (IOException ioe) { throw new CalendarServiceException(ioe); } catch (ParserException pe) { throw new CalendarServiceException(pe); } return calendarEvents; }
From source file:fr.itinerennes.bundler.tasks.ScheduleForStopTask.java
private ScheduleStopTime toScheduledStopTime(final StopTime gStopTime, final ServiceDate gServiceDate) { final ScheduleStopTime sst = new ScheduleStopTime(); final Calendar a = gServiceDate.getAsCalendar(TimeZone.getDefault()); final Calendar d = gServiceDate.getAsCalendar(TimeZone.getDefault()); a.add(Calendar.SECOND, gStopTime.getArrivalTime()); d.add(Calendar.SECOND, gStopTime.getDepartureTime()); sst.setArrivalTime(new Date(a.getTimeInMillis())); sst.setDepartureTime(new Date(d.getTimeInMillis())); sst.setHeadsign(gStopTime.getTrip().getTripHeadsign()); sst.setRoute(toRoute(gStopTime.getTrip().getRoute())); sst.setRouteId(sst.getRoute().getId()); sst.setServiceId(gStopTime.getTrip().getServiceId().toString()); sst.setTripId(gStopTime.getTrip().getId().toString()); return sst;/* w w w .j a v a 2 s. c om*/ }
From source file:de.kurashigegollub.dev.gcatest.Utils.java
public static DateTime getDateTimeNow() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0);/*ww w . j av a 2 s . c o m*/ c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); //Google's DateTime class works with GMT timezone internally and converts all passed in Date values to it. //see code here: //http://code.google.com/p/google-api-java-client/source/browse/google-api-client/src/main/java/com/google/api/client/util/DateTime.java?spec=svnf7334c6f6f7c0941306e18de989c90a053941669&r=f7334c6f6f7c0941306e18de989c90a053941669 //Therefore we have to apply our local timezone here so the calculated time will DateTime dtg = new DateTime(c.getTime(), TimeZone.getDefault()); // log.info("TimeZone: " + c.getTimeZone().getDisplayName()); // log.info("TimeZone: " + c.getTimeZone().getID()); // log.info("Date: " + getDateAsString(c.getTime())); // log.info("DateTime: " + getDateAsString(dtg)); // log.info("DateTime: " + dtg.toString()); // log.info("DateTime: " + dtg.toStringRfc3339()); return dtg; }