⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e318. formatting and parsing a time for a locale using default formats.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
Every locale has four default formats for formatting and parsing times. They are called SHORT, MEDIUM, LONG, and FULL. The SHORT format consists entirely of numbers while the FULL format contains most of the time components. There is also a default format called DEFAULT and is the same as MEDIUM. 
Note: This example formats dates using the default locale (which, in the author's case, is Locale.ENGLISH). If the example is run in a different locale, the text (e.g., month names) will not be the same. 

    // Format
    Locale locale = Locale.ITALIAN;
    Date date = new Date();
    
    String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date);
    // 22.33
    
    s = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale).format(date);
    // 22.33.03
    
    s = DateFormat.getTimeInstance(DateFormat.LONG, locale).format(date);
    // 22.33.03 PST
    
    s = DateFormat.getTimeInstance(DateFormat.FULL, locale).format(date);
    // 22.33.03 PST
    
    s = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale).format(date);
    // 22.33.03
    
    // Parse
    try {
        date = DateFormat.getTimeInstance(
            DateFormat.DEFAULT, locale).parse("22.33.03");
    } catch (ParseException e) {
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -