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
  • 相关阅读:
    MySQL概述
    Seleniumselenium基础入门
    MySQL数据库的安装与使用
    元素定位_id
    Selenium浏览器的前进、后退、刷新
    元素定位_tag_name
    Selenium浏览器操作_窗口大小设置
    元素定位_name
    搭建maven服务器(repository)
    使用dos命令生成目录树
  • 原文地址:https://www.cnblogs.com/borter/p/9613410.html
Copyright © 2011-2022 走看看