zoukankan      html  css  js  c++  java
  • Java如何以短格式显示月份?

    在Java中,如何显示短格式的月份名称?

    使用DateFormatSymbols().DateFormatSymbols类的getShortMonths()方法,本示例显示了几个月的简写名称。

    package com.yiibai;
    
    import java.text.SimpleDateFormat;
    import java.text.DateFormatSymbols;
    
    public class DisplayingMonthsShortFormat {
        public static void main(String[] args) {
            String[] shortMonths = new DateFormatSymbols().getShortMonths();
    
            for (int i = 0; i < (shortMonths.length - 1); i++) {
                String shortMonth = shortMonths[i];
                System.out.println("shortMonth = " + shortMonth);
            }
        }
    }
    
    Java

    上述代码示例将产生以下结果,结果将根据当前系统时间而有变化。

    shortMonth = 一月
    shortMonth = 二月
    shortMonth = 三月
    shortMonth = 四月
    shortMonth = 五月
    shortMonth = 六月
    shortMonth = 七月
    shortMonth = 八月
    shortMonth = 九月
    shortMonth = 十月
    shortMonth = 十一月
    shortMonth = 十二月
    
    Shell

    以下是日期,时间和短时间的另一个示例。

    package com.yiibai;
    
    import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    import java.util.Calendar;
    
    public class DisplayingMonthsShortFormat2 {
        public static void main(String[] argv) throws Exception {
            String str1 = "yyyy-MM-dd";
            Date d = Calendar.getInstance().getTime();
            SimpleDateFormat sdf = new SimpleDateFormat(str1, Locale.FRENCH);
            System.out.println(sdf.format(d));
            sdf = new SimpleDateFormat(str1, Locale.ENGLISH);
            System.out.println(sdf.format(d));
        }
    }
    
    Java

    上述代码示例将产生以下结果(结果取决于当前日期)。

    2017-09-17
    2017-09-17
  • 相关阅读:
    input 去除边框
    分页封装
    python后端继承序列化,不同访问形式返回不同结果
    解决vue前端不显示自定义字段
    Vue 获取后端多对多关联表信息
    vue 前段增删改查代码规范
    前段增删改查的应用
    ant-design-vue基础
    python 后端 数据库的创表及增删改查 简单使用
    配置Uwsgi+Nginx+Django+Vue
  • 原文地址:https://www.cnblogs.com/borter/p/9613410.html
Copyright © 2011-2022 走看看