List of usage examples for org.joda.time DateTime getMillisOfSecond
public int getMillisOfSecond()
From source file:org.gravidence.gravifon.util.DateTimeUtils.java
License:Open Source License
/** * Converts datetime object to array of UTC datetime fields.<p> * Given datetime object is casted to UTC.<p> * Resulting array content is as follows: <code>[yyyy,MM,dd,HH,mm,ss,SSS]</code>. * //from w w w .ja v a 2 s.c o m * @param value datetime object * @return array of UTC datetime fields */ public static int[] dateTimeToArray(DateTime value) { int[] result; if (value == null) { result = null; } else { result = new int[7]; DateTime valueUTC = value.toDateTime(DateTimeZone.UTC); result[0] = valueUTC.getYear(); result[1] = valueUTC.getMonthOfYear(); result[2] = valueUTC.getDayOfMonth(); result[3] = valueUTC.getHourOfDay(); result[4] = valueUTC.getMinuteOfHour(); result[5] = valueUTC.getSecondOfMinute(); result[6] = valueUTC.getMillisOfSecond(); } return result; }
From source file:org.graylog2.messagehandlers.syslog.SyslogEventHandler.java
License:Open Source License
/** * Handle an incoming syslog message: Output if in debug mode, store in MongoDB, ReceiveHooks * * @param syslogServer The syslog server * @param event The event to handle//from www. j a v a 2 s . c om */ public void event(SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event) { GELFMessage gelf = new GELFMessage(); // Print out debug information. if (event instanceof GraylogSyslogServerEvent) { GraylogSyslogServerEvent glEvent = (GraylogSyslogServerEvent) event; LOG.info("Received syslog message (via AMQP): " + event.getMessage()); LOG.info("AMQP queue: " + glEvent.getAmqpReceiverQueue()); gelf.addAdditionalData("_amqp_queue", glEvent.getAmqpReceiverQueue()); } else { LOG.info("Received syslog message: " + event.getMessage()); } LOG.info("Host: " + event.getHost()); LOG.info("Facility: " + event.getFacility() + " (" + Tools.syslogFacilityToReadable(event.getFacility()) + ")"); LOG.info("Level: " + event.getLevel() + " (" + Tools.syslogLevelToReadable(event.getLevel()) + ")"); LOG.info("Raw: " + new String(event.getRaw())); // Use JodaTime to easy get the milliseconds and construct a float. (This looks dumb but is the easiest and safest way) try { DateTime jt = new DateTime(event.getDate().getTime()); String unixTime = String.valueOf(event.getDate().getTime() / 1000L); String millis = String.valueOf(jt.getMillisOfSecond()); Double milliSecondTime = new Double(unixTime + "." + millis); gelf.setCreatedAt(milliSecondTime.doubleValue()); } catch (NumberFormatException e) { LOG.error("Could not determine milliseconds of syslog message. (NumberFormatException)"); } gelf.setConvertedFromSyslog(true); gelf.setVersion("0"); gelf.setShortMessage(event.getMessage()); gelf.setHost(event.getHost()); gelf.setFacility(Tools.syslogFacilityToReadable(event.getFacility())); gelf.setLevel(event.getLevel()); gelf.setRaw(event.getRaw()); try { SimpleGELFClientHandler gelfHandler = new SimpleGELFClientHandler(gelf); gelfHandler.handle(); } catch (Exception e) { // I don't care } }
From source file:org.graylog2.Tools.java
License:Open Source License
/** * * @return The current UTC UNIX timestamp with milliseconds. *///from www .ja v a 2 s . co m public static double getUTCTimestampWithMilliseconds() throws NumberFormatException { // Use JodaTime to easy get the milliseconds and construct a float. (This looks dumb but is the easiest and safest way) long now = System.currentTimeMillis(); DateTime jt = new DateTime(now); String unixTime = String.valueOf(now / 1000); String millis = String.valueOf(jt.getMillisOfSecond()); Double milliSecondTime = new Double(unixTime + "." + millis); return milliSecondTime.doubleValue(); }
From source file:org.hawkular.metrics.core.impl.DateTimeService.java
License:Apache License
public DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }// ww w . jav a 2s. c o m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.datetime.DateTimeService.java
License:Apache License
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/* w ww. j a v a 2 s. co m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.tasks.api.AbstractTrigger.java
License:Apache License
protected DateTime getExecutionTime(long time, Duration duration) { DateTime dt = new DateTime(time); Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*from w w w.ja v a 2 s . co m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapter.java
License:Apache License
/** * Get an XMLGregorianCalendar for the specified date. * * @param date/*from w ww . j av a 2s. c o m*/ * @return * @throws DatatypeConfigurationException */ protected XMLGregorianCalendar getXmlDate(DateTime date) throws DatatypeConfigurationException { // construct an XMLGregorianCalendar DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); XMLGregorianCalendar start = datatypeFactory.newXMLGregorianCalendar(); start.setYear(date.getYear()); start.setMonth(date.getMonthOfYear()); start.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(), date.getMillisOfSecond()); start.setDay(date.getDayOfMonth()); return start; }
From source file:org.jbpm.designer.web.server.SimulationServlet.java
License:Apache License
private String getDateString(long seDate) { Date d = new Date(seDate); DateTime dt = new DateTime(seDate); StringBuffer retBuf = new StringBuffer(); retBuf.append(dt.getYear()).append(","); retBuf.append(dt.getMonthOfYear()).append(","); retBuf.append(dt.getDayOfMonth()).append(","); retBuf.append(dt.getHourOfDay()).append(","); retBuf.append(dt.getMinuteOfHour()).append(","); retBuf.append(dt.getSecondOfMinute()).append(","); retBuf.append(dt.getMillisOfSecond()); return retBuf.toString(); }
From source file:org.jruby.ext.date.RubyDateTime.java
License:LGPL
@JRubyMethod // Time.new(year, mon, mday, hour, min, sec + sec_fraction, (@of * 86400.0)) public RubyTime to_time(ThreadContext context) { final Ruby runtime = context.runtime; DateTime dt = this.dt; dt = new DateTime(adjustJodaYear(dt.getYear()), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), dt.getMillisOfSecond(), RubyTime.getTimeZone(runtime, this.off)); RubyTime time = new RubyTime(runtime, runtime.getTime(), dt, true); if (subMillisNum != 0) { RubyNumeric usec = (RubyNumeric) subMillis(runtime).op_mul(context, RubyFixnum.newFixnum(runtime, 1_000_000)); time.setNSec(usec.getLongValue()); }//www .ja v a 2s .c o m return time; }
From source file:org.jruby.ext.date.TimeExt.java
License:LGPL
@JRubyMethod(name = "to_datetime") public static RubyDateTime to_datetime(ThreadContext context, IRubyObject self) { final RubyTime time = (RubyTime) self; DateTime dt = ((RubyTime) self).getDateTime(); long subMillisNum = 0, subMillisDen = 1; if (time.getNSec() != 0) { IRubyObject subMillis = RubyRational.newRationalCanonicalize(context, time.getNSec(), 1_000_000); if (subMillis instanceof RubyRational) { subMillisNum = ((RubyRational) subMillis).getNumerator().getLongValue(); subMillisDen = ((RubyRational) subMillis).getDenominator().getLongValue(); } else {// w w w. j av a2 s .c o m subMillisNum = ((RubyInteger) subMillis).getLongValue(); } } final int off = dt.getZone().getOffset(dt.getMillis()) / 1000; int year = dt.getYear(); if (year <= 0) year--; // JODA's Julian chronology (no year 0) if (year == 1582) { // take the "slow" path - JODA isn't adjusting for missing (reform) dates return calcAjdFromCivil(context, dt, off, subMillisNum, subMillisDen); } dt = new DateTime(year, dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), dt.getMillisOfSecond(), getChronology(context, ITALY, dt.getZone())); return new RubyDateTime(context.runtime, getDateTime(context.runtime), dt, off, ITALY, subMillisNum, subMillisDen); }