public static void main(String[] args) {
/*
* 以下代码用于向大家展示各个时间日期类对象的包含组件。
*/
java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
System.out.println(sqlDate.toString()); // 输出结果:2012-09-01
java.sql.Time sqlTime = new java.sql.Time(System.currentTimeMillis());
System.out.println(sqlTime.toString()); // 输出结果:12:35:11
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(System.currentTimeMillis());
System.out.println(sqlTimestamp.toString()); // 输出结果:2012-09-01 12:36:33.544
java.util.Date utilDate = new java.util.Date(System.currentTimeMillis());
System.out.println(utilDate.toString()); // 输出结果:Sat Sep 01 12:37:34 CST 2012
java.util.Calendar cl = java.util.Calendar.getInstance();
System.out.println(cl.getTime().toString()); // 输出结果:Sat Sep 01 12:39:51 CST 2012
}
package java.sql;
public class Date extends java.util.Date {
// 省略部分代码……
// Override all the time operations inherited from java.util.Date;
/**
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #setHours
*/
public int getHours() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #setMinutes
*/
public int getMinutes() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #setSeconds
*/
public int getSeconds() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #getHours
*/
public void setHours(int i) {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #getMinutes
*/
public void setMinutes(int i) {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #getSeconds
*/
public void setSeconds(int i) {
throw new java.lang.IllegalArgumentException();
}
/**
* Private serial version unique ID to ensure serialization
* compatibility.
*/
static final long serialVersionUID = 1511598038487230103L;
}
// 省略部分源代码……
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a year component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
* @see #setYear
*/
@Deprecated
public int getYear() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a month component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
* @see #setMonth
*/
@Deprecated
public int getMonth() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a day component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
*/
@Deprecated
public int getDay() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a date component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
* @see #setDate
*/
@Deprecated
public int getDate() {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a year component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
* @see #getYear
*/
@Deprecated
public void setYear(int i) {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a month component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
* @see #getMonth
*/
@Deprecated
public void setMonth(int i) {
throw new java.lang.IllegalArgumentException();
}
/**
* This method is deprecated and should not be used because SQL <code>TIME</code>
* values do not have a date component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this
* method is invoked
* @see #getDate
*/
@Deprecated
public void setDate(int i) {
throw new java.lang.IllegalArgumentException();
}
/**
* Private serial version unique ID to ensure serialization
* compatibility.
*/
static final long serialVersionUID = 8397324403548013681L;
}
public static void main(String[] args) {
/*
* 以下代码用于向大家展示各个时间日期类对象的包含组件。
*/
java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
System.out.println(sqlDate.toString()); // 输出结果:2012-09-01
java.sql.Time sqlTime = new java.sql.Time(System.currentTimeMillis());
System.out.println(sqlTime.toString()); // 输出结果:12:35:11
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(System.currentTimeMillis());
System.out.println(sqlTimestamp.toString()); // 输出结果:2012-09-01 12:36:33.544
java.util.Date utilDate = new java.util.Date(System.currentTimeMillis());
System.out.println(utilDate.toString()); // 输出结果:Sat Sep 01 12:37:34 CST 2012
java.util.Calendar cl = java.util.Calendar.getInstance();
System.out.println(cl.getTime().toString()); // 输出结果:Sat Sep 01 12:39:51 CST 2012
/*
* 以下代码用于试验java.sql.Date和java.sql.Time是否具有完整组件。
*/
System.out.println();
try {
System.out.println(sqlDate.getHours());
} catch (Exception e) {
System.out.println(e.getMessage()); // 输出 null
}
try {
System.out.println(sqlTime.getDate());
} catch (Exception e) {
System.out.println(e.getMessage()); // 输出 null
}
}
package java.util; import java.text.DateFormat; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.lang.ref.SoftReference; import sun.util.calendar.BaseCalendar; import sun.util.calendar.CalendarDate; import sun.util.calendar.CalendarSystem; import sun.util.calendar.CalendarUtils; import sun.util.calendar.Era; import sun.util.calendar.Gregorian; import sun.util.calendar.ZoneInfo;
package java.util; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OptionalDataException; import java.io.Serializable; import java.security.AccessControlContext; import java.security.AccessController; import java.security.PermissionCollection; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.security.ProtectionDomain; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import sun.util.BuddhistCalendar; import sun.util.calendar.ZoneInfo; import sun.util.resources.LocaleData;
public static void main(String[] args) {
/*
* 以下代码用于向大家展示各个时间日期类对象的包含组件。
*/
java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
System.out.println(sqlDate.toString()); // 输出结果:2012-09-01
java.sql.Time sqlTime = new java.sql.Time(System.currentTimeMillis());
System.out.println(sqlTime.toString()); // 输出结果:12:35:11
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(System.currentTimeMillis());
System.out.println(sqlTimestamp.toString()); // 输出结果:2012-09-01 12:36:33.544
java.util.Date utilDate = new java.util.Date(System.currentTimeMillis());
System.out.println(utilDate.toString()); // 输出结果:Sat Sep 01 12:37:34 CST 2012
java.util.Calendar cl = java.util.Calendar.getInstance();
System.out.println(cl.getTime().toString()); // 输出结果:Sat Sep 01 12:39:51 CST 2012
/*
* 以下代码用于试验java.sql.Date和java.sql.Time是否具有完整组件。
*/
System.out.println();
try {
System.out.println(sqlDate.getHours());
} catch (Exception e) {
System.out.println(e.getMessage()); // 输出 null
}
try {
System.out.println(sqlTime.getDate());
} catch (Exception e) {
System.out.println(e.getMessage()); // 输出 null
}
/*
* 下面的代码给大家展示时间日期的格式化。
*/
System.out.println();
java.text.DateFormat dateFormat = java.text.SimpleDateFormat.getInstance();
// java.util.Date原本的格式
System.out.println(utilDate.toString()); // 输出:Sat Sep 01 13:16:13 CST 2012
// java.util.Date格式化后的格式
System.out.println(dateFormat.format(sqlDate)); // 输出:12-9-1 下午1:16
System.out.println();
// 很多时候以上的结果并不是我们希望的,我们希望更加自由、更见简单的操作方式
// 此时,java.text.SimpleDateFormat就成了我们的不二选择
// SimpleDateFormat提供了无参和自定义格式参数的构造方法使我们能够轻松地实现自定义格式化
java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss a");
System.out.println(simpleDateFormat.format(sqlDate)); // 输出:2012-09-01 13:20:41 下午
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有