日期格式转换

案例:

    @Test
    void bbb(){
        String format = "MMM d, yyyy hh:mm:ss a zzz";
        // 创建“英文/美国”的Locale
        Locale localeUS = new Locale("en", "US");

        Date date = new Date();
        String format2 = DateUtil.format(date, format);
        System.out.println("format2 = " + format2);

        SimpleDateFormat formatA = new SimpleDateFormat(format, localeUS);
        String format1 = formatA.format(date);
        System.out.println("format2 = " + format1);
        // (四月 14, 2023 11:34 上午 +0800) 格式:"MMM d, yyyy hh:mm aa Z"
        // (四月 14, 2023 11:36:22 上午 +0800) 格式:"MMM d, yyyy hh:mm:ss aa Z"
        // (四月 14, 2023 06:01:09 下午 CST) 格式:"MMM d, yyyy hh:mm:ss a zzz"
        // (Apr 14, 2023 06:21:20 PM CST) 格式:"MMM d, yyyy hh:mm:ss a zzz" 注意:需要进行US的地区才能得到

        // 创建“简体中文”的Locale
        Locale localeCN = Locale.SIMPLIFIED_CHINESE;
        
        // 获取“简体中文”对应的date字符串
        String cn = DateFormat.getDateInstance(DateFormat.MEDIUM, localeCN).format(date);
        // 获取“英文/美国”对应的date字符串
        String us = DateFormat.getDateInstance(DateFormat.MEDIUM, localeUS).format(date);

        System.out.printf("cn=%s\nus=%s\n", cn, us);
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值