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
  • 相关阅读:
    Abaqus刚体建模方法
    Abaqus 幅值曲线—与时间相关的函数定义
    Abaqus/CAE 热-力耦合分析
    数据库设计要遵循的点
    c# 面向对象的编程思想
    领导要求你去做不属于你工作范围内的工作,你是答应还是委婉拒绝?
    工作总结&成长感悟
    jquery中的ajax方法参数
    swal() 弹出删除确认框
    serializearray()的具体使用
  • 原文地址:https://www.cnblogs.com/borter/p/9613410.html
Copyright © 2011-2022 走看看