Java 时间格式转换

Date to String

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startTime);

Date to DateTime

DateTime time = new DateTime(new Date());

Date to String

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format("2018-4-23 23:12:16");

Data to TimeStamp

new Timestamp(new Date().getTime())

DateTime To Calendar

Calendar calendar = Calendar.getInstance();    
dateTime = new DateTime(calendar);

DateTime to Date

Date date = time.toDate();

DateTime to String

String time = dateTime.toString("yyyy-MM-dd HH:mm:ss");

String to Data

Date date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2018-4-23 23:12:16");

String to DateTime

DateTimeFormatter format = DateTimeFormat .forPattern("yyyy-MM-dd HH:mm:ss");  
DateTime dateTime = DateTime.parse("2018-4-23 23:12:16", format);
posted @ 2023-03-10 11:03  lambertlt  阅读(12)  评论(0编辑  收藏  举报