时间处理问题……急啊,请各位大虾指点

yygywqf 2012-05-02 05:16:40
怎么样将这样的字符串“Jan 10 19:19:28 2012”转换为date格式。

我这样转换有问题,但不知道格式哪里错了:

String date = "Jan 10 19:19:28 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy");
long currdate = formatter.parse(date).getTime();
...全文
128 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yygywqf 2012-05-03
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]
Java code

public class TestDate {
public static void main(String[] args) throws Exception
{

String str="Jan 02 12:12:12 2012";
SimpleDateFormat formatter = new ……
[/Quote]
谢了,这个方法可解……
ZZZ5512536 2012-05-02
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]

说实话我是google加API做出来的。。。
[/Quote]

能抓到耗子就是好猫
sdojqy1122 2012-05-02
  • 打赏
  • 举报
回复
说实话我是google加API做出来的。。。
sdojqy1122 2012-05-02
  • 打赏
  • 举报
回复

public class TestDate {
public static void main(String[] args) throws Exception
{

String str="Jan 02 12:12:12 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd HH:mm:ss yyyy",Locale.ENGLISH);
Date ts = formatter.parse(str);
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy MM HH:mm:SS");
System.out.print(formatter1.format(ts));
}
}
JP_2012 2012-05-02
  • 打赏
  • 举报
回复

import java.text.SimpleDateFormat;
import java.util.Date;

public class Test {
public static void main(String[] aa) {
SimpleDateFormat dateformat1 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss E");
String a1 = dateformat1.format(new Date());
System.out.println("时间2:" + a1);
System.out.println(new Date().getYear() + 1900);

SimpleDateFormat dateformat2 = new SimpleDateFormat(
"yyyy年MM月dd日 HH时mm分ss秒 E ");
String a2 = dateformat2.format(new Date());
System.out.println("时间2:" + a2);
}
}


LZ自己看着用吧
yygywqf 2012-05-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
3楼 可解
[/Quote]
3楼的long d = Date.parse(date);方法是过时的,可惜我们的代码中不提倡使用过时的方法。
JP_2012 2012-05-02
  • 打赏
  • 举报
回复
3楼 可解
yygywqf 2012-05-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
Java code

public static void main(String[] args) {
String date = "Jan 10 19:19:28 2012";
long d = Date.parse(date);
System.out.println(d);
SimpleDateFormat f……
[/Quote]
楼上的Date.parse 我之前是用这方法,但为过时方法,我们代码中不能用过时的方法。

long d = Date.parse(date);

dreamhyz 2012-05-02
  • 打赏
  • 举报
回复

public class TestDate {
public static void main(String[] args) throws Exception
{

String date = "05 02 12:12:12 2012";
SimpleDateFormat formatter = new SimpleDateFormat("MM dd HH:mm:ss yyyy");
long currdate = formatter.parse(date).getTime();

System.out.println(currdate);

}
}




前后格式要对应,兄弟
JP_2012 2012-05-02
  • 打赏
  • 举报
回复
还有一个问题是 日期没有你那种解析的
sdojqy1122 2012-05-02
  • 打赏
  • 举报
回复

public static void main(String[] args) {
String date = "Jan 10 19:19:28 2012";
long d = Date.parse(date);
System.out.println(d);
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy MM dd HH:mm:SS");
String currdate;
currdate = formatter.format(d);
System.out.println(currdate);

}
JP_2012 2012-05-02
  • 打赏
  • 举报
回复
你传的值 有问题无法解析
dreamhyz 2012-05-02
  • 打赏
  • 举报
回复
貌似看到了3个M。。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧