java Date类

格式转换:

import java.util.Date;//Date类需要引用这个包

//得到的时间是国外的使用格式:Mon Oct 16 20:28:30 CST 2023
        Date date = new Date();
        System.out.println(date);

//date格式化得到2023-10-16 08:31:45 星期一
    ​​​​​​​SimpleDateFormat sdf = new SimpleDateFormat("YYY-MM-dd hh:mm:ss E");
    System.out.println(sdf.format(date));

转换后变转换前:

//转回成国外格式
        String s = "2023-10-14 20:16:16 星期六 ";//需要和定义的sdf格式一样,否则编译异常
        Date parse1 = sdf.parse(s);
        System.out.println(parse1);//Sat Jan 07 20:16:16 CST 202
        System.out.println(sdf.format(parse1));//2023-01-07 08:16:16 星期六
通过毫秒数得到时间:
Date d = new Date(99999999);
System.out.println(d);//Fri Jan 02 11:46:39 CST 1970

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值