android-Date 与 DateFormat 与 Calendar

来源:互联网 发布:ubuntu 14 vim配置 编辑:程序博客网 时间:2024/05/23 01:22



public class SimpleDateFormat extends DateFormat {}

public abstract class DateFormat extends Format {}


 Formats or parses dates and times.
格式化或解析日期和时间。

就是为了把date格式化到String. 

把String变成date。


Date很多操作都过时了,需要Calendar实现拆分。需要Dateformat来显示。


详见 Date.class 源码 http://blog.csdn.net/ofreelander/article/details/45267501

 * <p>Instances of this class are suitable for comparison, but little else.
 * Use {@link java.text.DateFormat} to format a {@code Date} for display to a human.
 * Use {@link Calendar} to break down a {@code Date} if you need to extract fields such
 * as the current month or day of week, or to construct a {@code Date} from a broken-down
 * time. That is: this class' deprecated display-related functionality is now provided
 * by {@code DateFormat}, and this class' deprecated computational functionality is
 * now provided by {@code Calendar}. Both of these other classes (and their subclasses)
 * allow you to interpret a {@code Date} in a given time zone.
 *
 * <p>Note that, surprisingly, instances of this class are mutable.

 */

这个类的实例适用于比较,也仅限于此。为了给人展示时间,用java.text.DateFormat来格式化一个Date实例。如果你需要获取某个域,例如当前月份和日期,使用Calendar来划分Date。也可以从一个分解的时间造一个Date。

也就是说,这个类与显示相关的过时的功能现在由DateFormat来实现,这个类与计算相关的过时的功能由Calendar来实现。Calendar和DateFormat这两个类(包括子类)允许你解析Date在给定的时区里。


Calendar.class 源码

**
 * {@code Calendar} is an abstract base class for converting between a
 * {@code Date} object and a set of integer fields such as
 * {@code YEAR}, {@code MONTH}, {@code DAY},
 * {@code HOUR}, and so on. (A {@code Date} object represents a
 * specific instant in time with millisecond precision. See {@link Date} for
 * information about the {@code Date} class.)
 *Calendar是一个抽象基类,用来转换Date对象和一系列整形数。例如year,month 等等。一个Date对象代表一个特定的毫秒精度的时刻。
 * <p>
 * Subclasses of {@code Calendar} interpret a {@code Date}
 * according to the rules of a specific calendar system.
 *根据calendar系统的规则,Calendar的子类解析Date对象。
 * <p>
 * Like other locale-sensitive classes, {@code Calendar} provides a class
 * method, {@code getInstance}, for getting a default instance of
 * this class for general use. {@code Calendar}'s {@code getInstance} method
 * returns a calendar whose locale is based on system settings and whose time fields
 * have been initialized with the current date and time: <blockquote>

 *像其他的地域敏感的类,Calendar提供了一个方法getInstance()来得到一个类的实例,它的区域设置是基于系统设置,时间域已经被初始化为当前的日期和时间。

 * <pre>Calendar rightNow = Calendar.getInstance()</pre>

 *

DateFormat.class 源码

/**
 * Utility class for producing strings with formatted date/time.
 *格式化日期时间到字符串的工具类。
 * <p>Most callers should avoid supplying their own format strings to this
 * class' {@code format} methods and rely on the correctly localized ones
 * supplied by the system. This class' factory methods return
 * appropriately-localized {@link java.text.DateFormat} instances, suitable
 * for both formatting and parsing dates. For the canonical documentation
 * of format strings, see {@link java.text.SimpleDateFormat}.
 *调用者应该避免提供自己的字符串给format()方法。应该使用系统提供的本地化的一个。

这个类的工厂方法返回适当的本地化的Dateformat实例,来实现格式化和解析dates。
 * <p>In cases where the system does not provide a suitable pattern,
 * this class offers the {@link #getBestDateTimePattern} method.
 * 在系统没有提供合适的格式化模板时,类提供了getBestDateTimePattern()方法。





0 0
原创粉丝点击