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 HH:mm:ss"; 
        SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); 
        System.out.println(sdf.format(date)); 
    }
}

运行结果为:

2020-03-23 15:43:23

发布了233 篇原创文章 · 获赞 504 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/weixin_44015669/article/details/105049974