将日期从 yyyy-mm-dd 转换为日-月-日期
我的日期格式为 2011-11-02
。从这个日期开始,我们如何知道Day-of-week
、Month
和Day-of-month
,就像这种格式Wednesday-Nov-02
,从日历还是任何其他方式?
I have date in this format 2011-11-02
. From this date, how can we know the Day-of-week
, Month
and Day-of-month
, like in this format Wednesday-Nov-02
, from calendar or any other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果是普通的java,您将使用两个 SimpleDateFormats - 一个到读取和写入:
输出:
作为一个函数(即静态方法),它看起来像:
警告:
不要试图将
read
或write
写入静态字段,以节省每次方法调用时实例化它们的麻烦,因为 SimpleDateFormat 不是线程安全的!
,在查阅Blackberry Java 5.0 API doc后,似乎是
写的。格式
部分应该与黑莓的 SimpleDateFormat 配合使用,但是您需要使用其他东西来解析日期...HttpDateParser 看起来很有前途。我没有安装 JDK,但请尝试以下操作:If it were normal java, you would use two SimpleDateFormats - one to read and one to write:
Output:
As a function (ie static method) it would look like:
Warning:
Do not be tempted to make
read
orwrite
into static fields to save instantiating them every method invocation, because SimpleDateFormat is not thread safe!Edited
However, after consulting the Blackberry Java 5.0 API doc, it seems the
write.format
part should work with blackberry's SimpleDateFormat, but you'll need to parse the date using something else... HttpDateParser looks promising. I don't have that JDK installed, but try this: