如何解析 new Date().toString() 的输出 [英] how to parse output of new Date().toString()

查看:41
本文介绍了如何解析 new Date().toString() 的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种日期格式(可能是 SimpleDateFormat),它可以解析我在 Date 对象上调用 toString() 时获得的可靠输出.我的德语(!)系统上的输出是:Sun Dec 12 13:45:12 CET 2010",所以它似乎不尊重语言环境,这似乎很容易.

I need a date format (maybe SimpleDateFormat) that parses reliable the output I get when I call toString() on a Date object. Output on my german(!) system is: "Sun Dec 12 13:45:12 CET 2010", so it doesn't seem to honor locales, which seems to make it easy.

有人吗?

推荐答案

该格式在 Date#toString().

将此Date 对象转换为以下形式的String:

Converts this Date object to a String of the form:

dow mon dd hh:mm:ss zzz yyyy

所以,在 SimpleDateFormat 模式术语:

So, in SimpleDateFormat pattern terms:

EEE MMM dd HH:mm:ss zzz yyyy


与问题无关,我想知道首先使用 Date#toString() 而不是 SimpleDateFormat#format() 是否不是一个坏主意输出日期.我会考虑直接在那里修复它.


Unrelated to the problem, I wonder if it wasn't in first place a bad idea to use Date#toString() instead of SimpleDateFormat#format() to output dates. I would consider to fix it straight there.

这篇关于如何解析 new Date().toString() 的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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