List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:Main.java
public static long getDayInUTC(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time);/*w w w .ja v a2 s. com*/ cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.setTimeZone(TimeZone.getTimeZone("UTC")); return cal.getTimeInMillis(); }
From source file:mk.finki.ranggo.aggregator.Aggregator.java
private static void update(String date, ContentsAggregator aggregator) { //if 'date' is null, the method aggregates contents published on the current date //if it is, it aggregates the data published on that date //parameter format is dd.mm.yyyy, assumed UTC+0 //parse or generate date object Date dateObj = null;//from w w w .jav a 2s .c om if (date != null) { try { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.mm.yyyy"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); dateObj = simpleDateFormat.parse(date); } catch (ParseException e) { } } else { //no date parameter, default case is today Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); dateObj = calendar.getTime(); } if (dateObj != null) { try { aggregator.aggregateGoogleNewsRSSFeed(dateObj); } catch (ContentsAggregatorException exception) { //log this } try { aggregator.aggregateHuffingtonPost(); } catch (ContentsAggregatorException exception) { //log this } try { aggregator.aggregateDnevnik(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateKurir(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateLibertas(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateNovaTV(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateRepublika(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateTelma(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateUtrinskiVesnik(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateVecher(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateVest(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateVesti24(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateNYTimes(dateObj); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateTheGuardian(dateObj); } catch (ContentsAggregatorException exception) { } } }
From source file:org.eclipse.smarthome.binding.astro.internal.util.PropertyUtils.java
/** * Returns the state of the channel.//from w w w. j a v a2 s . c om */ public static State getState(ChannelUID channelUID, AstroChannelConfig config, Object instance) throws Exception { Object value = getPropertyValue(channelUID, instance); if (value == null) { return UnDefType.UNDEF; } else if (value instanceof State) { return (State) value; } else if (value instanceof Calendar) { Calendar cal = (Calendar) value; GregorianCalendar gregorianCal = (GregorianCalendar) DateTimeUtils.applyConfig(cal, config); cal.setTimeZone(TimeZone.getTimeZone(timeZoneProvider.getTimeZone())); ZonedDateTime zoned = gregorianCal.toZonedDateTime().withFixedOffsetZone(); return new DateTimeType(zoned); } else if (value instanceof Number) { BigDecimal decimalValue = new BigDecimal(value.toString()).setScale(2, RoundingMode.HALF_UP); return new DecimalType(decimalValue); } else if (value instanceof String || value instanceof Enum) { return new StringType(value.toString()); } else { throw new IllegalStateException("Unsupported value type " + value.getClass().getSimpleName()); } }
From source file:alfio.datamapper.QueryType.java
private static SqlParameterSource extractParameters(Method m, Object[] args) { Annotation[][] parameterAnnotations = m.getParameterAnnotations(); if (parameterAnnotations == null || parameterAnnotations.length == 0) { return new EmptySqlParameterSource(); }/*from w w w .j ava 2 s . com*/ MapSqlParameterSource ps = new MapSqlParameterSource(); Class<?>[] parameterTypes = m.getParameterTypes(); for (int i = 0; i < args.length; i++) { String name = parameterName(parameterAnnotations[i]); if (name != null) { if (args[i] != null && ZonedDateTime.class.isAssignableFrom(parameterTypes[i])) { ZonedDateTime dateTime = ZonedDateTime.class.cast(args[i]); final ZonedDateTime utc = dateTime.withZoneSameInstant(ZoneId.of("UTC")); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("UTC")); c.setTimeInMillis(utc.toInstant().toEpochMilli()); ps.addValue(name, c, Types.TIMESTAMP); } else { ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i])); } } } return ps; }
From source file:org.apache.falcon.expression.ExpressionHelper.java
private static int getDayOffset(String weekDayName) { int day;/*from ww w. j a v a 2 s.c o m*/ Calendar nominalTime = Calendar.getInstance(); nominalTime.setTimeZone(TimeZone.getTimeZone("UTC")); nominalTime.setTime(referenceDate.get()); int currentWeekDay = nominalTime.get(Calendar.DAY_OF_WEEK); int weekDay = DayOfWeek.valueOf(weekDayName).ordinal() + 1; //to map to Calendar.SUNDAY ... day = weekDay - currentWeekDay; if (weekDay > currentWeekDay) { day = day - 7; } return day; }
From source file:com.hemou.android.util.StrUtils.java
/** * {@link https://en.wikipedia.org/wiki/List_of_time_zones_by_country} * @param time/* w w w. ja va 2 s .c om*/ * @return */ public static String convertTimeWithTimeZome(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.setTimeInMillis(time); return (cal.get(Calendar.YEAR) + " " + (cal.get(Calendar.MONTH) + 1) + " " + cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE)); }
From source file:com.siphyc.utils.Utilities.java
public static Date combineDateTime(Date date, Date time) { Calendar dateCalendar = GregorianCalendar.getInstance(); dateCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); dateCalendar.setTime(date);/* w ww . j av a 2 s. c o m*/ Calendar timeCalendar = GregorianCalendar.getInstance(); timeCalendar.setTime(time); Calendar combinedCalendar = GregorianCalendar.getInstance(); // date combinedCalendar.set(Calendar.YEAR, dateCalendar.get(Calendar.YEAR)); combinedCalendar.set(Calendar.MONTH, dateCalendar.get(Calendar.MONTH)); combinedCalendar.set(Calendar.DAY_OF_MONTH, dateCalendar.get(Calendar.DAY_OF_MONTH)); //time combinedCalendar.set(Calendar.HOUR_OF_DAY, timeCalendar.get(Calendar.HOUR_OF_DAY)); combinedCalendar.set(Calendar.MINUTE, timeCalendar.get(Calendar.MINUTE)); return combinedCalendar.getTime(); }
From source file:com.pureinfo.srm.project.ProjectToFinishRemindJob.java
private static Date getNMonthLater(int _n) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getDefault()); cal.roll(Calendar.MONTH, _n); return cal.getTime(); }
From source file:DateTimeUtil.java
/** * Get date from given date stamp./*ww w. j a v a2s . c o m*/ * Format: yyyy-mm-ddThh:mm:ssZ * @param stamp * @return */ public static Date getDateFromUniversalDateStamp(String stamp) { // Log.debug("Parsing date: " + stamp); String year = stamp.substring(0, 4); String month = stamp.substring(5, 7); String day = stamp.substring(8, 10); String hour = stamp.substring(11, 13); String minutes = stamp.substring(14, 16); String seconds = stamp.substring(17, 19); //Log.debug(year+"-"+month+"-"+day+"T"+hour+":"+minutes+":"+seconds); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UNC+0")); cal.set(Calendar.YEAR, Integer.parseInt(year)); cal.set(Calendar.MONTH, Integer.parseInt(month) - 1); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day)); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour)); cal.set(Calendar.MINUTE, Integer.parseInt(minutes)); cal.set(Calendar.SECOND, Integer.parseInt(seconds)); Date date = cal.getTime(); return date; }
From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>// w w w .j a va 2 s .com * YYYY-MM-DDTHH:MI:SS.SSS+09:00 ? ?(:2007-02-13T10:25:05.986+07:00) ? GregorianCalendar ?. * </pre> * * @param stringTypeDate YYYY-MM-DDTHH:MI:SS.SSS+09:00 ? ?(:2007-02-13T10:25:05.986+07:00) * @return ? GregorianCalendar */ private static GregorianCalendar gmtStringToGregorianCalendar(String stringTypeDate) throws DatatypeConfigurationException { String yyyy = stringTypeDate.substring(0, 4); String mm = stringTypeDate.substring(5, 7); String dd = stringTypeDate.substring(8, 10); String hh = "00"; String mi = "00"; String ss = "00"; String ms = "00"; String tz = null; if (stringTypeDate.length() > 23) { hh = stringTypeDate.substring(11, 13); mi = stringTypeDate.substring(14, 16); ss = stringTypeDate.substring(17, 19); ms = stringTypeDate.substring(20, 23); tz = stringTypeDate.substring(23); } else { tz = stringTypeDate.substring(10); //tz = "+09:00"; } if (tz.equals("Z")) { tz = "UTC"; } else { tz = "GMT" + tz; } int iyyyy = Integer.parseInt(yyyy); int imm = Integer.parseInt(mm) - 1; int idd = Integer.parseInt(dd); int ihh = Integer.parseInt(hh); int imi = Integer.parseInt(mi); int iss = Integer.parseInt(ss); int ims = Integer.parseInt(ms); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone(tz)); c.set(iyyyy, imm, idd, ihh, imi, iss); c.set(Calendar.MILLISECOND, ims); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(c.getTime()); cal.setTimeZone(TimeZone.getTimeZone("ROK")); return cal; }