Java Code Examples for org.joda.time.MutableDateTime#getMillis()
The following examples show how to use
org.joda.time.MutableDateTime#getMillis() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Time_11_ZoneInfoCompiler_s.java From coming with MIT License | 6 votes |
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
Example 2
Source File: Time_11_ZoneInfoCompiler_t.java From coming with MIT License | 6 votes |
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
Example 3
Source File: ZoneInfoCompiler.java From astor with GNU General Public License v2.0 | 6 votes |
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
Example 4
Source File: ZoneInfoCompiler.java From astor with GNU General Public License v2.0 | 6 votes |
static int parseTime(String str) { DateTimeFormatter p = ISODateTimeFormat.hourMinuteSecondFraction(); MutableDateTime mdt = new MutableDateTime(0, getLenientISOChronology()); int pos = 0; if (str.startsWith("-")) { pos = 1; } int newPos = p.parseInto(mdt, str, pos); if (newPos == ~pos) { throw new IllegalArgumentException(str); } int millis = (int)mdt.getMillis(); if (pos == 1) { millis = -millis; } return millis; }
Example 5
Source File: ValueConverterTest.java From components with Apache License 2.0 | 5 votes |
@Test public void testXMLGregorianCalendarConverter() throws Exception { DateTimeZone tz1 = DateTimeZone.getDefault(); MutableDateTime dateTime1 = new MutableDateTime(tz1); dateTime1.setDate(System.currentTimeMillis()); Long controlValue1 = dateTime1.getMillis(); XMLGregorianCalendar xmlCalendar1 = datatypeFactory.newXMLGregorianCalendar(); xmlCalendar1.setYear(dateTime1.getYear()); xmlCalendar1.setMonth(dateTime1.getMonthOfYear()); xmlCalendar1.setDay(dateTime1.getDayOfMonth()); xmlCalendar1.setHour(dateTime1.getHourOfDay()); xmlCalendar1.setMinute(dateTime1.getMinuteOfHour()); xmlCalendar1.setSecond(dateTime1.getSecondOfMinute()); xmlCalendar1.setMillisecond(dateTime1.getMillisOfSecond()); xmlCalendar1.setTimezone(tz1.toTimeZone().getOffset(dateTime1.getMillis()) / 60000); FieldDesc fieldInfo = typeDesc.getField("tranDate"); NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName()); AvroConverter<XMLGregorianCalendar, Long> converter1 = (AvroConverter<XMLGregorianCalendar, Long>) transducer.getValueConverter(fieldInfo); assertEquals(AvroUtils._logicalTimestamp(), converter1.getSchema()); assertEquals(XMLGregorianCalendar.class, converter1.getDatumClass()); assertEquals(controlValue1, converter1.convertToAvro(xmlCalendar1)); assertEquals(xmlCalendar1, converter1.convertToDatum(controlValue1)); AvroConverter<XMLGregorianCalendar, Object> converter2 = (AvroConverter<XMLGregorianCalendar, Object>) transducer.getValueConverter(fieldInfo); assertEquals(xmlCalendar1, converter2.convertToDatum(new Date(controlValue1.longValue()))); assertNull(converter1.convertToAvro(null)); }
Example 6
Source File: AlarmScheduler.java From BaldPhone with Apache License 2.0 | 4 votes |
static long nextTimeAlarmWillWorkInMs(@NonNull Alarm alarm) { final MutableDateTime mDateTime = MutableDateTime.now(); { //creating a date of today with the hours and minutes of the alarm mDateTime.setMillisOfSecond(0); mDateTime.setSecondOfMinute(0); mDateTime.setHourOfDay(alarm.getHour()); mDateTime.setMinuteOfHour(alarm.getMinute()); } final int baldDay = getBaldDay(); { //today or one time if ((alarm.getDays() & baldDay) == baldDay) {//today may have an alarm if ((alarm.getDays() == baldDay)) { if (mDateTime.isBeforeNow()) mDateTime.addWeeks(1); //next week if today's time already passed return mDateTime.getMillis(); } else { if (mDateTime.isAfterNow()) return mDateTime.getMillis(); } } else if (alarm.getDays() == -1) { if (mDateTime.isBeforeNow()) mDateTime.addDays(1); return mDateTime.getMillis(); } } int selectedBaldDay = baldDay; { //find next day for (int i = baldDay << 1; i != baldDay; i <<= 1) { if (i > D.Days.SATURDAY) i = D.Days.SUNDAY; if ((alarm.getDays() & i) == i) { selectedBaldDay = i; break; } } } int day = baldDayToJodaDay(selectedBaldDay); mDateTime.setDayOfWeek(day); if (mDateTime.isBeforeNow()) { mDateTime.addWeeks(1); } return mDateTime.getMillis(); }
Example 7
Source File: ReminderScheduler.java From BaldPhone with Apache License 2.0 | 4 votes |
private static long nextTimeReminderWillWorkInMs(@NonNull Reminder reminder, Context context) { final MutableDateTime mDateTime = MutableDateTime.now(); { //creating a date of today with the hours and minutes of the alarm mDateTime.setMillisOfSecond(0); mDateTime.setSecondOfMinute(0); mDateTime.setHourOfDay(BPrefs.getHour(reminder.getStartingTime(), context)); mDateTime.setMinuteOfHour(BPrefs.getMinute(reminder.getStartingTime(), context)); } final int baldDay = getBaldDay(); final int days = reminder.getDays(); { //today or one time if ((days & baldDay) == baldDay) {//today may have an alarm if ((days == baldDay)) { if (mDateTime.isBeforeNow()) mDateTime.addWeeks(1); //next week if today's time already passed return mDateTime.getMillis(); } else { if (mDateTime.isAfterNow()) return mDateTime.getMillis(); } } else if (days == -1) { if (mDateTime.isBeforeNow()) mDateTime.addDays(1); return mDateTime.getMillis(); } } int selectedBaldDay = baldDay; { //find next day for (int i = baldDay << 1; i != baldDay; i <<= 1) { if (i > D.Days.SATURDAY) i = D.Days.SUNDAY; if ((days & i) == i) { selectedBaldDay = i; break; } } } int day = baldDayToJodaDay(selectedBaldDay); mDateTime.setDayOfWeek(day); if (mDateTime.isBeforeNow()) { mDateTime.addWeeks(1); } return mDateTime.getMillis(); }
Example 8
Source File: MDateAndTime.java From sql-layer with GNU Affero General Public License v3.0 | 4 votes |
/** Encode {@code dt} as a MySQL internal TIMESTAMP. Range is unchecked. */ public static int getTimestamp(long[] dt, String tz) { MutableDateTime dateTime = toJodaDateTime(dt, tz); return (int)(dateTime.getMillis() / 1000L); }