Java中的隐秘RFC3339 DateTime到Date [英] Covert RFC3339 DateTime to Date in java

查看:559
本文介绍了Java中的隐秘RFC3339 DateTime到Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏 RFC 3339 com.google.api.client.util.DateTime到Java中的DateTime.

How to covert the RFC 3339 com.google.api.client.util.DateTime to DateTime in java.

例如我得到的是"2014-07-21T16:35:27.000Z",我需要将其转换为"2014年7月15日下午6:07:25"格式.

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.

反正有转换吗?

这是我尝试过的.

我已将DateandTime保存为字符串在mongo db中.

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);
           }        

现在要更新日期,我正在获取Rfc3339格式的日期,我必须将其转换为java.util.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);

}

推荐答案

如果我了解您的问题,则可以使用

If I understand your question, you can use SimpleDateFormat like so,

String in = "2014-07-21T16:35:27.000Z";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
System.out.println(sdf.parse(in));

这篇关于Java中的隐秘RFC3339 DateTime到Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆