SimpleDateFormat 这个时间格式化的类
可以 时间->字符串,也可以 字符串-> 时间.
import java.sql.Timestamp;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Format {
public static void main(String[] args) {
try {
String time = "2012-02-21T13:21:59";
Format f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date d = f.parse(time);
Timestamp ts = new Timestamp(d.getTime());
System.out.println(ts);
} catch (ParseException e) {
e.printStackTrace();
}
}
}字符串转化为Timestamp
最新推荐文章于 2024-08-21 10:08:41 发布
本文介绍如何使用Java中的SimpleDateFormat类进行时间与字符串之间的转换。通过示例代码展示了将特定格式的时间字符串转换为Date对象的过程,并进一步将其转换为Timestamp类型。
2168

被折叠的 条评论
为什么被折叠?



