您的位置:首页 > 其它

SimpleDateFormat 12 小时制和24小时制实现

2016-12-12 15:41 260 查看

SimpleDateFormat 12 小时制和24小时制实现

// SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
// SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制

看测试代码:

/**
* 版权所有 (c) 2016,
*/
package helloTest;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* 类说明:
*
* <pre>
* Modify Information:
* Author Date Description
* ============ =========== ============================
* 2016-6-21 Create this file
* </pre>
*
*/
public class Test {

public static void main(String[] args) {

String valueString = "20161031161121711";
// SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
// SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
SimpleDateFormat origFormat = new SimpleDateFormat("yyyyMMddhhmmssSSS");//17位精确到ms
SimpleDateFormat destFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
System.out.println(destFormat.format(origFormat.parse(valueString)));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: