List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:com.clevercloud.bianca.lib.date.DateModule.java
License:Open Source License
/** * Returns the parsed date.//from w ww . j a v a 2 s . c o m */ public Value strptime(Env env, String date, String format) { ArrayValueImpl array = new ArrayValueImpl(); DateTimeFormatterBuilder fb = new DateTimeFormatterBuilder(); int length = format.length(); for (int i = 0; i < length; i++) { char ch = format.charAt(i); if (ch != '%') { fb.appendLiteral(ch); continue; } switch (format.charAt(++i)) { case 'a': fb.appendDayOfWeekShortText(); break; case 'A': fb.appendDayOfWeekText(); break; case 'h': case 'b': fb.appendMonthOfYearShortText(); ; break; case 'B': fb.appendMonthOfYearText(); break; // TODO: case 'c' case 'C': fb.appendCenturyOfEra(2, 2); break; case 'd': fb.appendDayOfMonth(2); break; case 'D': fb.appendMonthOfYear(2); fb.appendLiteral('/'); fb.appendDayOfMonth(2); fb.appendLiteral('/'); fb.appendYear(2, 2); break; // TODO: case 'e' case 'F': fb.appendYear(4, 4); fb.appendLiteral('-'); fb.appendMonthOfYear(2); fb.appendLiteral('-'); fb.appendDayOfMonth(2); break; // TODO: case 'g' // TODO: case 'G' case 'H': fb.appendHourOfDay(2); break; case 'I': fb.appendHourOfHalfday(2); break; case 'j': fb.appendDayOfYear(3); break; // TODO: case 'l' case 'm': fb.appendMonthOfYear(2); break; case 'M': fb.appendMinuteOfHour(2); break; case 'n': fb.appendLiteral("\n"); break; case 'p': case 'P': fb.appendHalfdayOfDayText(); break; case 'r': fb.appendHourOfHalfday(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); fb.appendLiteral(' '); fb.appendHalfdayOfDayText(); break; case 'R': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); break; // TODO: case 's' case 'S': fb.appendSecondOfMinute(2); break; case 't': fb.appendLiteral("\t"); break; case 'T': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); break; // TODO: case 'u' // TODO: case 'U' // TODO: case 'V' // TODO: case 'w' // TODO: case 'W' // TODO: case 'x' // TODO: case 'X' case 'y': fb.appendYear(2, 2); break; case 'Y': fb.appendYear(4, 4); break; case 'z': fb.appendTimeZoneOffset(null, true, 2, 2); break; case 'Z': fb.appendTimeZoneName(); break; case '%': fb.appendLiteral('%'); break; default: fb.appendLiteral(ch); } } DateTimeFormatter dtf = fb.toFormatter().withLocale(Locale.getDefault()).withOffsetParsed(); org.joda.time.DateTime dt = new org.joda.time.DateTime(); String unparsed = ""; try { dt = dtf.parseDateTime(date); } catch (IllegalArgumentException e) { String delims = "[\"]+"; String[] splits = e.getMessage().split(delims); unparsed = unparsed.concat(splits[3]); } // According to manual strptime(3) if (dt.getCenturyOfEra() == 0) { if (dt.getYear() > 68) { dt = dt.withCenturyOfEra(19); } else { dt = dt.withCenturyOfEra(20); } } array.put("tm_sec", dt.getSecondOfMinute()); array.put("tm_min", dt.getMinuteOfHour()); array.put("tm_hour", dt.getHourOfDay()); array.put("tm_mday", dt.getDayOfMonth()); array.put("tm_mon", dt.getMonthOfYear() - 1); array.put("tm_year", dt.getYearOfCentury() + ((dt.getCenturyOfEra() - 19) * 100)); // Years since 1900 array.put("tm_wday", dt.getDayOfWeek() % 7); array.put("tm_yday", dt.getDayOfYear() - 1); array.put("unparsed", unparsed); return array; }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest day. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>/* w ww .j a v a 2 s. c o m*/ * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 00:00:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest day. */ public static DateTime floorToDay(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), 0, 0, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest hour. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>//from w w w .j a v a 2 s . co m * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:00:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest hour. */ public static DateTime floorToHour(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), 0, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest specified period in minutes. For example, if * a period of 5 minutes is requested, a time of "2009-06-24 13:24:51.476 -8:00" * would return a datetime of "2009-06-24 13:20:00.000 -8:00". The time zone of the * returned DateTime instance will be the same as the argument. Similar to a * floor() function on a float.<br> * NOTE: While any period in minutes between 1 and 59 can be passed into this * method, its only useful if the value can be evenly divided into 60 to make * it as useful as possible.<br>/*from w ww .j a va 2 s . com*/ * Examples: * <ul> * <li>null -> null * <li>5: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:35:00.000 -8:00" * <li>10: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00" * <li>15: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00" * <li>20: "2009-06-24 13:39:51.476 UTC" -> "2009-06-24 13:20:00.000 UTC" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest period in minutes. */ public static DateTime floorToMinutePeriod(DateTime value, int periodInMinutes) { if (value == null) { return null; } if (periodInMinutes <= 0 || periodInMinutes > 59) { throw new IllegalArgumentException("period in minutes must be > 0 and <= 59"); } int min = value.getMinuteOfHour(); min = (min / periodInMinutes) * periodInMinutes; return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), min, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest minute. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>/*from w w w .java 2 s. c om*/ * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest minute. */ public static DateTime floorToMinute(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), value.getMinuteOfHour(), 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest second. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>/*from w ww . j av a 2s . co m*/ * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:51.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest second. */ public static DateTime floorToSecond(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute(), 0, value.getZone()); }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Checks if is last date./*from w ww . j a v a 2s . com*/ * * @return true, if is last date */ public static boolean isLastDate() { DateTime startDate = new DateTime(DateTimeZone.UTC); int max = startDate.dayOfMonth().getMaximumValue(); int current = startDate.getDayOfMonth(); return current == max; }
From source file:com.core.beans.HomeBean.java
public String formatDate(Date d) { DateTime time = new DateTime(d); return time.getDayOfMonth() + "/" + (time.getMonthOfYear() < 10 ? "0" : "") + time.getMonthOfYear() + "/" + time.getYear() + " " + (time.getHourOfDay() < 9 ? "0" : "") + time.getHourOfDay() + ":" + (time.getMinuteOfHour() < 9 ? "0" : "") + time.getMinuteOfHour(); }
From source file:com.core.meka.Util.java
public static String now() { DateTime n = new DateTime(new Date()); return n.getDayOfMonth() + "/" + n.getMonthOfYear() + "/" + n.getYear() + " " + (n.getHourOfDay() < 10 ? "0" + n.getHourOfDay() : n.getHourOfDay()) + ":" + (n.getMinuteOfHour() < 10 ? "0" + n.getMinuteOfHour() : n.getMinuteOfHour()); }
From source file:com.core.meka.Util.java
public static String fecha(Date fechaAdquisicion) { String result = "Sin especificar"; if (fechaAdquisicion != null) { DateTime d = new DateTime(fechaAdquisicion); result = d.getDayOfMonth() + "/" + d.getMonthOfYear() + "/" + d.getYear(); }/*from w w w .j a v a 2s. c o m*/ return result; }