欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java快速获取格式化的日期字符串

程序员文章站 2022-08-03 19:12:46
1、使用Date对象 String dateStr = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()); 2、使用Calendar对象 String dateStr = new SimpleDateFormat("yyyy ......

1、使用date对象

  string datestr = new simpledateformat("yyyy/mm/dd hh:mm:ss").format(new date());

2、使用calendar对象

  string datestr = new simpledateformat("yyyy/mm/dd hh:mm:ss").format(calendar.getinstance().gettime());

3、使用localdatetime对象

  string datestr = localdatetime.now().format(datetimeformatter.ofpattern("yyyy/mm/dd hh:mm:ss"));