格式的日期与System.out.format : 日期格式 « 数据类型 « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » 数据类型 » 日期格式 
2. 38. 20. 格式的日期与System.out.format
/*
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Sun Microsystems nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.util.Calendar;
import java.util.Locale;

public class TestFormat {

  public static void main(String[] args) {
    long n = 461012;
    System.out.format("%d%n", n);
    System.out.format("%08d%n", n);
    System.out.format("%+8d%n", n);
    System.out.format("%,8d%n", n);
    System.out.format("%+,8d%n%n", n);

    double pi = Math.PI;
    System.out.format("%f%n", pi);
    System.out.format("%.3f%n", pi);
    System.out.format("%10.3f%n", pi);
    System.out.format("%-10.3f%n", pi);
    System.out.format(Locale.FRANCE, "%-10.4f%n%n", pi);

    Calendar c = Calendar.getInstance();
    System.out.format("%tB %te, %tY%n", c, c, c);
    System.out.format("%tl:%tM %tp%n", c, c, c);
    System.out.format("%tD%n", c);
  }
}
2. 38. 日期格式
2. 38. 1. 日期解析和格式DateFormat
2. 38. 2. 解析时间使用自定义格式
2. 38. 3. 剖析了自定义格式
2. 38. 4. 解析的默认格式
2. 38. 5. Parse string date value input with SimpleDateFormat('dd-MMM-yy')
2. 38. 6. 解析的日期和时间
2. 38. 7. Parse string date value input with SimpleDateFormat('E, dd MMM yyyy HH:mm:ss Z')
2. 38. 8. Parse string date value with default format: DateFormat.getDateInstance(DateFormat.DEFAULT)
2. 38. 9. Leniency
2. 38. 10. 格式化字符串符号SimpleDateFormat
2. 38. 11. SimpleDateFormat: hh:mm:ss, dd MMM yyyy hh:mm:ss zzz, E MMM dd yyyy
2. 38. 12. 格式日期采用YYYYMMDD
2. 38. 13. 表示在任期期间
2. 38. 14. 日期格式SimpleDateFormat
2. 38. 15. Demonstrate date formats with different DateFormat constants
2. 38. 16. 显示时间格式。
2. 38. 17. DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM)
2. 38. 18. 打印出当前的日期和时间
2. 38. 19. 日期时代变化
2. 38. 20. 格式的日期与System.out.format
2. 38. 21. 简单日期格式化
2. 38. 22. 格式化日期和时间
2. 38. 23. Four different date formats for four countries: US, UK, GERMANY, FRANCE
2. 38. 24. 各种日期格式各种日期格式
2. 38. 25. 在短格式显示日期名字
2. 38. 26. 短格式显示日期天,月
2. 38. 27. 格式的日期到日/月/年
2. 38. 28. Format current date and time with the SimpleDateFormat: dd/MM/yyyy
2. 38. 29. Format current date and time with the SimpleDateFormat: HH:mm:ss
2. 38. 30. 格式符号SimpleDateFormat
2. 38. 31. 格式化时间使用自定义格式
2. 38. 32. 更改日期格式符号
2. 38. 33. 获得短名单显示一个月的名称
2. 38. 34. Get a List of Weekday Names
2. 38. 35. Get a List of Short Weekday Names
2. 38. 36. 时间在12小时格式
2. 38. 37. 时间在24小时格式
2. 38. 38. 日期和时间与一个月
2. 38. 39. 日期和时间同一天,一个月长格式
2. 38. 40. Output current time: %tc
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.