WELCOME

任何一个伟大的目标,都有一个微不足道的开始。
a:hover { cursor:url(https://files.cnblogs.com/files/laoguantongxiegogo/click_24px_1231393_easyicon.net.ico),auto; } body { cursor:url(https://files.cnblogs.com/files/laoguantongxiegogo/pointer_24px_1231389_easyicon.net.ico),auto; }

Class SimpleDateFormat(util)

构造方法有:

* public SimpleDateFormat():构造一个SimpleDateFormat,使用默认模式和日期格式
* public SimpleDateFormat(String pattern):构造一个SimpleDateFormat使用给定的模式和默认的日期格式

 

y表示年

M表示月

d表示日

HH:mm:ss 则表示时分秒

 

把日期转为指定格式的字符串

 

创建一个构造方法我们先确定返回值和参数 即

 public static String dTs(Date date,String format){} 注意:这里我们创建完是需要导包的,我们做的是util类的

接着我们需要根据上面方法创建对象

 SimpleDateFormat sdf = new SimpleDateFormat(format); 

这里我们把日期传过来,转为指定格式,并返回

 String s = sdf.format(date);return s;

 接下来我们来调用这个方法,先定义一个main方法

 public static void main(String[] args){} 

接着创建日期对象

 Date d = new Date(); 

开始调用

 String s1 = Datecs.dateToString(d,"yyyy年MM月dd日 HH:mm:ss");  注意:这里面等号后面的Datecs是上面定义的一个类名

输出

 System.out.println(s1); 

结果如下

 

posted @ 2021-12-23 20:17  liheihei  阅读(42)  评论(0编辑  收藏  举报

载入天数...载入时分秒...