java时间格式化

2017-11-03  本文已影响0人  0_cc

1、将long类型的时间字符串,如:newDate().getTime(),转化为“yyyy-MM-dd HH:mm:ss”格式的字符串

public static String longStrToDateStr(String time) {

        SimpleDateFormat simpleDateFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        return simpleDateFormat.format(newDate(newLong(time)));

}

2、将“yyyy-MM-dd HH:mm:ss”格式的时间字符串,转化为long类型的时间字符串

public static String dateStrToLongStr(String time)throwsParseException {

        SimpleDateFormat simpleDateFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date = simpleDateFormat.parse(time);

        return String.valueOf(date.getTime());

}

上一篇 下一篇

猜你喜欢

热点阅读