首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Timestamp跟String的相互转换[转]

2012-10-24 
Timestamp和String的相互转换[转]用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数

Timestamp和String的相互转换[转]

用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式。

????? Timestamp转化为String:SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式,不显示毫秒Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间String str = df.format(now);????? String转化为Timestamp:SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());Timestamp ts = Timestamp.valueOf(time);

本文出自 “Strive to Live” 博客,请务必保留此出处http://zeroyang.blog.51cto.com/259838/106748

本文出自 51CTO.COM技术博客

热点排行