How to covert the RFC 3339 com.google.api.client.util.DateTime to DateTime in java.
For example I am getting "2014-07-21T16:35:27.000Z" which I need to covert into "Jul 15, 2014 6:07:25 PM" format.
There is anyway to convert this?
This is what i tried.
I have saved the DateandTime as a string in mongo db.
public Map<String, String> getYouTubeLastFetchDateTime(String key) {
System.out.println("Inserting data first time....");
Date nowDate = new Date();
Date dateBefore = new Date(nowDate.getTime() - 7 * 24 * 3600
* 1000);
Utils utils = new Utils();
DBCollection collection = utils.getStaging().getCollection(
DB_YOUTUBE_COLLECTION_NAME);
if (null != collection) {
CIPKeyWord keyword = new CIPKeyWord();
keyword.setLastFeachedTime(dateBefore);
keyword.setName(key);
DBObject dbObject = getDBObject(keyword);
collection.save(dbObject);
// ObjectId id = (ObjectId) dbObject.get("_id");
}
queryObject = new BasicDBObject().append("name", key);
result = dao.findOne(queryObject, DB_YOUTUBE_COLLECTION_NAME);
lastFetchedTime = (String) result.get("lastFeachedTime");
nextPageToken = (String) result.get("nextPageToken");
prevPageToken = (String) result.get("prevPageToken");
}
private String getKeyword() {
Map<String, String> paginationInfo = utils
.getYouTubeLastFetchDateTime(key);
String dateTime = paginationInfo.get("lastFechedDate");
date = new SimpleDateFormat("MMMM dd, yyyy", Locale.ENGLISH)
.parse(dateTime);
com.google.api.client.util.DateTime.DateTime lastFechedDate = new DateTime(date);
}
Now to update the date I am getting the date in Rfc3339 format which i have to convert to java.util.Date format.
public static boolean updateYouTubeLastFetchDate(String keyword,
DateTime newFetchTime, String nextPageToken, String prevPageToken){
BasicDBObject updateDocument = new BasicDBObject();
updateDocument.append(
"$set",
new BasicDBObject().append("nextPageToken",
nextPageToken).append("prevPageToken",
prevPageToken)
.append("lastFeachedTime",
newFetchTime.toString())
);
CIPDBUtils utils = new CIPDBUtils();
DBCollection collection = utils.getStaging().getCollection(
DB_YOUTUBE_COLLECTION_NAME);
collection.update(queryObject, updateDocument);
}