Java: 格式化时间(SimpleDateFormat)
如何使用 SimpleDateFormat 类的 format(date) 方法来格式化时间,如下所示:
package csdn1;
import java.text.SimpleDateFormat;
import java.util.Date;
public class 时间csdn1 {
public static void main(String[] args){
Date date = new Date();
String strDateFormat = “yyyy-MM-dd HHss”;
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
System.out.println(sdf.format(date));
}
}
运行结果为:
2020-03-23 15:43:23
还没有评论,来说两句吧...