List of usage examples for org.joda.time DateTime withZone
public DateTime withZone(DateTimeZone newZone)
From source file:com.thinkbiganalytics.DateTimeUtil.java
License:Apache License
public static DateTime convertToUTC(DateTime date) { DateTimeZone dtZone = DateTimeZone.forID("UTC"); DateTime utc = date.withZone(dtZone); return new DateTime(utc); }
From source file:com.thinkbiganalytics.DateTimeUtil.java
License:Apache License
public static DateTime convertToUTC(Long time) { DateTimeZone dtZone = DateTimeZone.forID("UTC"); DateTime date = new DateTime(time); DateTime utc = date.withZone(dtZone); return new DateTime(utc); }
From source file:com.tomtom.speedtools.time.UTCTime.java
License:Apache License
/** * Return time in time zone UTC.//from w w w. ja va 2 s . co m * * @param time Source time, Joda time. * @return Same time in UTC time. */ @Nonnull public static DateTime from(@Nonnull final DateTime time) { assert time != null; return time.withZone(DateTimeZone.UTC); }
From source file:com.tremolosecurity.lastmile.LastMile.java
License:Apache License
public LastMile(String uri, DateTime notBefore, DateTime notAfter, int loginLevel, String authChain) throws URISyntaxException { this();//w w w. j a v a2 s . c om this.request = new Request(); this.token = new Token(); this.request.setId(Long.toString(sr.nextLong())); this.request.setUri(URLDecoder.decode(uri)); this.request.setLoginLevel(loginLevel); this.request.setAuthChain(authChain); this.request.setNotBefore(notBefore.withZone(DateTimeZone.UTC).toString()); this.request.setNotAfter(notAfter.withZone(DateTimeZone.UTC).toString()); }
From source file:com.wellsandwhistles.android.redditsp.common.SRTime.java
License:Open Source License
public static String formatDurationFrom(final Context context, final long startTime) { final String space = " "; final String comma = ","; final String separator = comma + space; final long endTime = utcCurrentTimeMillis(); final DateTime dateTime = new DateTime(endTime); final DateTime localDateTime = dateTime.withZone(DateTimeZone.getDefault()); Period period = new Duration(startTime, endTime).toPeriodTo(localDateTime); PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendYears().appendSuffix(space) .appendSuffix(context.getString(R.string.time_year), context.getString(R.string.time_years)) .appendSeparator(separator).appendMonths().appendSuffix(space) .appendSuffix(context.getString(R.string.time_month), context.getString(R.string.time_months)) .appendSeparator(separator).appendDays().appendSuffix(space) .appendSuffix(context.getString(R.string.time_day), context.getString(R.string.time_days)) .appendSeparator(separator).appendHours().appendSuffix(space) .appendSuffix(context.getString(R.string.time_hour), context.getString(R.string.time_hours)) .appendSeparator(separator).appendMinutes().appendSuffix(space) .appendSuffix(context.getString(R.string.time_min), context.getString(R.string.time_mins)) .appendSeparator(separator).appendSeconds().appendSuffix(space) .appendSuffix(context.getString(R.string.time_sec), context.getString(R.string.time_secs)) .appendSeparator(separator).appendMillis().appendSuffix(space) .appendSuffix(context.getString(R.string.time_ms)).toFormatter(); String duration = periodFormatter.print(period.normalizedStandard(PeriodType.yearMonthDayTime())); List<String> parts = Arrays.asList(duration.split(comma)); if (parts.size() >= 2) { duration = parts.get(0) + comma + parts.get(1); }// ww w.j a v a2s.c om return String.format(context.getString(R.string.time_ago), duration); }
From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java
License:Open Source License
/** * Convert to local time.//from w w w . j a v a 2s . c o m * * @param timeOffset the time offset * @param time the time * @return the string */ public String convertToLocalTime(String timeOffset, String time) { Integer offsetValue = Integer.parseInt(timeOffset); log.debug("Offset value = " + offsetValue); DateTimeZone systemTimeZone = DateTimeZone.getDefault(); log.debug("system time zone " + systemTimeZone.toString()); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); DateTime systemDateTime = formatter.parseDateTime(time); log.debug("system date time " + systemDateTime.toString()); systemDateTime = systemDateTime.withZoneRetainFields(systemTimeZone); log.debug("system date time after adding systemtimezone === " + systemDateTime.toString()); int hours = -1 * offsetValue / 60; int minutes = offsetValue % 60; minutes = Math.abs(minutes); DateTimeZone localTimeZone = DateTimeZone.forOffsetHoursMinutes(hours, minutes); log.debug("Local time zone ==== " + localTimeZone.toString()); DateTime convertedDateTime = systemDateTime.withZone(localTimeZone); String convertedDateTimeString = formatter.print(convertedDateTime); log.debug("converted time :" + convertedDateTimeString); return convertedDateTimeString; }
From source file:com.yahoo.bard.webservice.data.time.ZonedTimeGrain.java
License:Apache License
/** * Use the inner grain's round function to round a {@link org.joda.time.DateTime}, but use the bucketing of this * grain's timezone rather than the one from the date time itself. * * @param dateTime The time being rounded * * @return the time, as rounded by the inner time grain and adjusted into this grain's time zone. *//*from w w w.j a v a 2 s . com*/ @Override public DateTime roundFloor(DateTime dateTime) { return baseTimeGrain.roundFloor(dateTime.withZone(timeZone)).withZone(timeZone); }
From source file:com.yahoo.bard.webservice.data.time.ZonedTimeGrain.java
License:Apache License
@Override public boolean aligns(DateTime dateTime) { return dateTime.withZone(timeZone).equals(roundFloor(dateTime)); }
From source file:com.yourmediashelf.fedora.util.DateUtility.java
License:Open Source License
/** * Formats a {@link DateTime} as an xsd:dateTime in canonical form. * * <p>Note: fractional seconds are only supported to a maximum of three * digits.</p>//from www . j a v a 2 s. c om * * @param dateTime * @return An xsd:dateTime (in UTC) representation of date. * @see "http://www.w3.org/TR/xmlschema11-2/#dateTime" */ public static String getXSDDateTime(DateTime dateTime) { return dateTime.withZone(DateTimeZone.UTC).toString(getXSDFormatter(dateTime)); }
From source file:controllers.Api.Statistic.java
License:Open Source License
public static Result getStatisticDayStats(Integer id) { // Variables//ww w. j ava2 s .c o m Integer index = 0, slideHour, yesterdayHour; DateTime slideDayTime, yesterdayDayTime; List<models.StatisticDay> statisticsDay = models.StatisticDay.find.where().eq("slide.slide_id", id).order() .asc("updateTime").findList(); Iterator<models.StatisticDay> statisticsDayIterator = statisticsDay.iterator(); // Yesterday Time Calc yesterdayDayTime = (new DateTime()).withZone(DateTimeZone.forID(session("timezone"))); yesterdayDayTime = yesterdayDayTime.minusHours(23); yesterdayHour = yesterdayDayTime.getHourOfDay(); // 0 Liste initialisieren List<Integer> statisticsDayReturn = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // Iterate List while (statisticsDayIterator.hasNext()) { models.StatisticDay statisticDayObject = statisticsDayIterator.next(); // Slide Time Calc slideDayTime = statisticDayObject.updateTime; slideDayTime = slideDayTime.withZone(DateTimeZone.forID(session("timezone"))); slideHour = slideDayTime.getHourOfDay(); // Because of long to int exceptionhandling try { if (slideHour == yesterdayHour) { index = statisticsDayReturn.size() - 1; } else if (slideHour > yesterdayHour) { index = (slideHour - yesterdayHour); } else if (slideHour < yesterdayHour) { index = (24 - (yesterdayHour - slideHour)) % 24; } statisticsDayReturn.set(index, statisticDayObject.views.intValue()); } catch (Exception e) { return badRequest(e.getMessage()); } } return ok(Json.toJson(statisticsDayReturn)); }