List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:com.google.devtools.moe.client.svn.SvnRevisionHistory.java
License:Apache License
/** * Helper function for parseMetadata/* w w w . j a v a 2 s. com*/ */ public RevisionMetadata parseMetadataNodeList(String revId, NodeList nlEntries, ImmutableList<Revision> parents) { String author = "None"; DateTime date = new DateTime(0L); // Unix epoch String description = "None"; for (int i = 0; i < nlEntries.getLength(); i++) { Node currNode = nlEntries.item(i); if (currNode.getNodeName().equals("author")) { author = currNode.getTextContent(); } if (currNode.getNodeName().equals("date")) { date = ISODateTimeFormat.dateTime().parseDateTime(currNode.getTextContent()); } if (currNode.getNodeName().equals("msg")) { description = currNode.getTextContent(); } } return RevisionMetadata.builder().id(revId).author(author).date(date).description(description) .withParents(parents).build(); }
From source file:com.google.soxlib.Utility.java
License:Apache License
/** * Get the time now in a string format suitable for use in SOX timestamp * fields.//from ww w .j a v a 2 s.c o m * * @return UTC timestamp to the nearest millisecond as a string. */ public static final String getTimestampNow() { DateTime now = new DateTime(DateTimeZone.UTC); return now.toString(ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC)); }
From source file:com.google.soxlib.Utility.java
License:Apache License
/** * Convert from "unix time" (utc milliseconds since 1970) into a string format * for use in SOX timestamp fields./*from w ww . ja v a 2 s . c o m*/ * * @param timestampMsUtc utc time in milliseconds since Jan 1, 1970 (aka unix * time). * @return UTC timestamp to the nearest millisecond as a string. */ public static final String getTimestampFromUnixTime(long timestampMsUtc) { DateTime dt = new DateTime(timestampMsUtc, DateTimeZone.UTC); return dt.toString(ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC)); }
From source file:com.google.soxlib.Utility.java
License:Apache License
/** * Verify that the string provided is a valid RFC 3339 timestamp string and * converts the string into the UTC timezone for use by the SOX library. * * @param timestamp string to be verified. * @return timestamp converted to UTC in the SOX format. * @throws IllegalArgumentException if the string cannot be converted to UTC. *//*w w w .j a va 2 s. com*/ public static final String verifyTimestamp(String timestamp) throws IllegalArgumentException { Matcher m = Utility.SIMPLE_TIMESTAMP_CHECK.matcher(timestamp); if (!m.find()) { throw new IllegalArgumentException("timestamp not valid"); } // convert entered value to the ISO standard and make that // the official value DateTime dt; try { dt = new DateTime(timestamp); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("timestamp not valid"); } return dt.toString(ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC)); }
From source file:com.helger.html.hc.html5.HCTime.java
License:Apache License
@Nonnull public HCTime setAsDateAndTime(@Nonnull final LocalDateTime aDateTime) { m_sDatetime = ISODateTimeFormat.dateTime().print(aDateTime); return this; }
From source file:com.helger.html.hc.html5.HCTime.java
License:Apache License
@Nonnull public HCTime setAsDateAndTime(@Nonnull final DateTime aDateTime) { m_sDatetime = ISODateTimeFormat.dateTime().print(aDateTime); return this; }
From source file:com.hust.duc.businessobjects.db.SubscriptionsDb.java
License:Open Source License
/** * Check if the given channel has new videos (by looking into the {@link SubscriptionsVideosTable} * [i.e. video cache table])./* ww w . j a v a 2 s .com*/ * * @param channel Channel to check. * * @return True if the user hasn't visited the channel and new videos have been uploaded in the * meantime; false otherwise. */ public boolean channelHasNewVideos(YouTubeChannel channel) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String query = String.format("SELECT COUNT(*) FROM %s WHERE %s = ? AND %s > ?", SubscriptionsVideosTable.TABLE_NAME, SubscriptionsVideosTable.COL_CHANNEL_ID, SubscriptionsVideosTable.COL_YOUTUBE_VIDEO_DATE); Cursor cursor = SubscriptionsDb.getSubscriptionsDb().getReadableDatabase().rawQuery(query, new String[] { channel.getId(), fmt.parseDateTime(new DateTime(new Date(channel.getLastVisitTime())).toString()).toString() }); boolean channelHasNewVideos = false; if (cursor.moveToFirst()) channelHasNewVideos = cursor.getInt(0) > 0; cursor.close(); return channelHasNewVideos; }
From source file:com.hust.duc.businessobjects.db.SubscriptionsDb.java
License:Open Source License
/** * Loop through each video saved in the passed {@link YouTubeChannel} and save it into the database, if it's not already been saved * @param channel/*from w w w. j a v a2 s.com*/ */ public void saveChannelVideos(YouTubeChannel channel) { Gson gson = new Gson(); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); for (YouTubeVideo video : channel.getYouTubeVideos()) { if (!hasVideo(video)) { ContentValues values = new ContentValues(); values.put(SubscriptionsVideosTable.COL_CHANNEL_ID, channel.getId()); values.put(SubscriptionsVideosTable.COL_YOUTUBE_VIDEO_ID, video.getId()); values.put(SubscriptionsVideosTable.COL_YOUTUBE_VIDEO, gson.toJson(video).getBytes()); values.put(SubscriptionsVideosTable.COL_YOUTUBE_VIDEO_DATE, fmt.parseDateTime(video.getPublishDate().toStringRfc3339()).toString()); getWritableDatabase().insert(SubscriptionsVideosTable.TABLE_NAME, null, values); } } }
From source file:com.kana.connect.server.receiver.SMSKeywordDispatchReplyHandler.java
License:Apache License
/** * Helper method that transforms an SMPP Message into an XML document */// w w w . j a va2s. com public static String smppToXml(SmppReceiverMessage msg) { SMPPRequest smppReq = msg.getSmppRequest(); StringBuffer buf = new StringBuffer(); buf.append("<smpp>\n"); // smpp header // numeric values do not need to be escaped buf.append("<header>"); buf.append("<command_id>").append(smppReq.getCommandId()).append("</command_id>"); buf.append("<sequence_number>").append(smppReq.getSequenceNum()).append("</sequence_number>"); buf.append("</header>\n"); // smpp source Address smppSource = smppReq.getSource(); buf.append("<source>"); buf.append("<ton>").append(smppSource.getTON()).append("</ton>"); buf.append("<npi>").append(smppSource.getNPI()).append("</npi>"); String srcAddr = smppSource.getAddress(); srcAddr = StringEscapeUtils.escapeXml11(srcAddr); buf.append("<address>").append(srcAddr).append("</address>"); buf.append("</source>\n"); // smpp dest Address smppDest = smppReq.getDestination(); buf.append("<destination>"); buf.append("<ton>").append(smppDest.getTON()).append("</ton>"); buf.append("<npi>").append(smppDest.getNPI()).append("</npi>"); String dstAddr = smppDest.getAddress(); dstAddr = StringEscapeUtils.escapeXml11(dstAddr); buf.append("<address>").append(dstAddr).append("</address>"); buf.append("</destination>\n"); // message id String msgId = smppReq.getMessageId(); if (msgId == null) { msgId = ""; } msgId = StringEscapeUtils.escapeXml11(msgId); buf.append("<messageid>").append(msgId).append("</messageid>\n"); // smpp message String msgText = smppReq.getMessageText(); msgText = StringEscapeUtils.escapeXml11(msgText); buf.append("<message>"); buf.append(msgText); buf.append("</message>\n"); // base64 message msgText = smppReq.getMessageText(); msgText = Base64.encodeBase64String(msgText.getBytes()); buf.append("<messageBase64>"); buf.append(msgText); buf.append("</messageBase64>\n"); // // timestamps in different formats // long now = System.currentTimeMillis(); // ISO8601 http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html DateTimeFormatter isoFormat = ISODateTimeFormat.dateTime(); isoFormat.withZoneUTC(); String headerTimestamp = isoFormat.print(now); headerTimestamp = StringEscapeUtils.escapeXml11(headerTimestamp); // custom format http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html DateTimeFormatter otherFormat = DateTimeFormat.forPattern("ddMMYYYYHHmmz"); String payloadTimestamp = otherFormat.print(now); payloadTimestamp = StringEscapeUtils.escapeXml11(payloadTimestamp); buf.append("<headertimestamp>").append(headerTimestamp).append("</headertimestamp>"); buf.append("<payloadtimestamp>").append(payloadTimestamp).append("</payloadtimestamp>"); buf.append("</smpp>\n"); return buf.toString(); }
From source file:com.kikini.logging.simpledb.SimpleDBWriter.java
License:Apache License
/** * Set the time zone to use when writing the time column. The default is the * system time zone.// www . java 2s. co m * * @param timeZone */ public void setTimeZone(DateTimeZone timeZone) { timeFormatter = ISODateTimeFormat.dateTime().withZone(timeZone); }