/*
输出引用类型的数据就要调用Object中的toString方法
一般是输出内存地址,若不是内存地址,则说明调用该方法的方法已经把toString方法重写了
获取系统当前时间
*/
import java.util.Date;
import java.text.SimpleDateFormat;
public class fuck10{
public static void main(String[] args){
Date nowtime=new Date();
System.out.println(nowtime);//Sat May 12 10:52:26 CST 2018
//以上对中国人不友好
//引入 格式化日期
//java.util.Date--->String
//日期格式:
// yyyy年mm月dd日hh时mm分ss秒
//创建日期格式化对象
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
//开始格式化 Date--->String
String strTime=sdf.format(nowtime);
System.out.println(strTime);
//currentTimeMillis()获取从1970年到现在的毫秒数
//String和Date格式的互相转换
//字符串=sdf.format(日期)
//日期=sdf.parse(字符串)
}
}
输出引用类型的数据就要调用Object中的toString方法
一般是输出内存地址,若不是内存地址,则说明调用该方法的方法已经把toString方法重写了
获取系统当前时间
*/
import java.util.Date;
import java.text.SimpleDateFormat;
public class fuck10{
public static void main(String[] args){
Date nowtime=new Date();
System.out.println(nowtime);//Sat May 12 10:52:26 CST 2018
//以上对中国人不友好
//引入 格式化日期
//java.util.Date--->String
//日期格式:
// yyyy年mm月dd日hh时mm分ss秒
//创建日期格式化对象
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
//开始格式化 Date--->String
String strTime=sdf.format(nowtime);
System.out.println(strTime);
//currentTimeMillis()获取从1970年到现在的毫秒数
//String和Date格式的互相转换
//字符串=sdf.format(日期)
//日期=sdf.parse(字符串)
}
}
本文通过一个Java示例展示了如何使用SimpleDateFormat类来格式化日期,将默认的日期输出格式转换为更易读的形式,并提供了从日期到字符串及从字符串到日期的转换方法。
1803

被折叠的 条评论
为什么被折叠?



