Java日期格式化

Java日期格式化

Java日期格式化

 

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class CX {

public static void main(String[] args) throws ParseException {

SimpleDateFormat sdf;

Date date; String s, s2 ;

// Jul 20, 2016 2:05:09 pm

String ds = “Jul 20, 2016 2:05:09 pm”;

date = new Date();

sdf = new SimpleDateFormat(“MMMMM dd,yyyy hh:mm:ss a”, Locale.ENGLISH );

s = sdf.format(date);

System.out.println(s);

date = sdf.parse(s);

System.out.println(“date = ” + date);

date = sdf.parse(ds);

System.out.println(“date2 = ” + date);

sdf = new SimpleDateFormat(“MMM dd,yyyy hh:mm:ss aa”, Locale.ENGLISH);

s = sdf.format(date); System.out.println(s);

date = sdf.parse(s);

System.out.println(“date = ” + date);

date = sdf.parse(ds);

System.out.println(“date2 = ” + date); }
}

输出:

June 22,2017 03:33:48 PM

date = Thu Jun 22 15:33:48 CST 2017

date2 = Wed Jul 20 14:05:09 CST 2016

Jul 20,2016 02:05:09 PM

date = Wed Jul 20 14:05:09 CST 2016

date2 = Wed Jul 20 14:05:09 CST 2016

好烂啊有点差凑合看看还不错很精彩 (No Ratings Yet)
Loading...
333 views

发表评论

电子邮件地址不会被公开。 必填项已用*标注

跳至工具栏