在JAVA中解析RFC 2822日期

编程入门 行业动态 更新时间:2024-10-27 06:27:18
本文介绍了在JAVA中解析RFC 2822日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要解析Java的日期的RFC 2822字符串表示形式。一个示例字符串在这里:

I need to parse an RFC 2822 string representation of a date in Java. An example string is here:

2010年3月13日星期六11:29:05 -0800

Sat, 13 Mar 2010 11:29:05 -0800

看起来很讨厌,所以我想确保我正在做的一切正确,并会遇到奇怪的问题后,日期被解释错误通过AM-PM /军事时间问题,UTC时间问题,我不期待的问题等...

It looks pretty nasty so I wanted to make sure I was doing everything right and would run into weird problems later with the date being interpreted wrong either through AM-PM/Military time problems, UTC time problems, problems I don't anticipate, etc...

谢谢!

推荐答案

这是一个快速的代码,可以做你所要求的(使用 SimpleDateFormat )

This is quick code that does what you ask (using SimpleDateFormat)

String rfcDate = "Sat, 13 Mar 2010 11:29:05 -0800"; String pattern = "EEE, dd MMM yyyy HH:mm:ss Z"; SimpleDateFormat format = new SimpleDateFormat(pattern); Date javaDate = format.parse(rfcDate); //Done.

PS。我没有在这里处理异常和并发(因为SimpleDateFormat在解析日期时不同步)。

PS. I've not dealt with exceptions and concurrency here (as SimpleDateFormat is not synchronized when parsing date).

更多推荐

在JAVA中解析RFC 2822日期

本文发布于:2023-11-03 16:52:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   JAVA   RFC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!