java解析类sql_java.sql.Date类解析java13

/*

* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.

* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

*继承链

java.lang.Object

java.util.Date

java.sql.Date

java.sql.Date提供了毫秒值的薄层封装,对应于数据库中的date类型。其毫秒值相对于19700101 00:00:00.000 GMT而言。

*

*

*/

package java.sql;

import java.time.Instant;

import java.time.LocalDate;

/**

*

A thin wrapper around a millisecond value that allows

* JDBC to identify this as an SQL DATE value.  A

* milliseconds value represents the number of milliseconds that

* have passed since January 1, 1970 00:00:00.000 GMT.

*

* To conform with the definition of SQL DATE, the

* millisecond values wrapped by a java.sql.Date instance

* must be 'normalized' by setting the

* hours, minutes, seconds, and milliseconds to zero in the particular

* time zone with which the instance is associated.

*

* @since 1.1

*/

public class Date extends java.util.Date {

/**

* Constructs a Date object initialized with the given

* year, month, and day.

*

* The result is undefined if a given argument is out of bounds.

*

* @param year the year minus 1900; must be 0 to 8099. (Note that

*        8099 is 9999 minus 1900.)

* @param month 0 to 11

* @param day 1 to 31

* @deprecated instead use the constructor Date(long date)

*/

@Deprecated(since="1.2")//从1.2开始弃用

public Date(int year, int month, int day) {

super(year, month, day);

}

/**

* Constructs a Date object using the given milliseconds

* time value.  If the given milliseconds value contains time

* information, the driver will set the time components to the

* time in the default time zone (the time zone of the Java virtual

* machine running the application) that corresponds to zero GMT.

*

* @param date milliseconds since January 1, 1970, 00:00:00 GMT not

*        to exceed the milliseconds representation for the year 8099.

*        A negative number indicates the number of milliseconds

*        before January 1, 1970, 00:00:00 GMT.

参数为long类型 毫秒值,代表从19700101 00:00:00.000毫秒之后或之前过了多长时间,负值表示之前。得到的时间不包含时分秒毫秒。

*/

public Date(long date) {

// If the millisecond date value contains time info, mask it out.

super(date);

}

/**

* Sets an existing Date object

* using the given milliseconds time value.

* If the given milliseconds value contains time information,

* the driver will set the time components to the

* time in the default time zone (the time zone of the Java virtual

* machine running the application) that corresponds to zero GMT.

*

* @param date milliseconds since January 1, 1970, 00:00:00 GMT not

*        to exceed the milliseconds representation for the year 8099.

*        A negative number indicates the number of milliseconds

*        before January 1, 1970, 00:00:00 GMT.

赋值,只有日期部分,不含时间部分

*/

public void setTime(long date) {

// If the millisecond date value contains time info, mask it out.

super.setTime(date);

}

/**

* Converts a string in JDBC date escape format to

* a Date value.

*

* @param s a String object representing a date in

*        in the format "yyyy-[m]m-[d]d". The leading zero for mm

* and dd may also be omitted.

* @return a java.sql.Date object representing the

*         given date

* @throws IllegalArgumentException if the date given is not in the

*         JDBC date escape format (yyyy-[m]m-[d]d)

将格式为yyyy-mm-dd的字符串转为date型,字符串的格式必须为yyyy-mm-dd其中月和日可以为一位,即2019-03-06,可为2019-3-6,

非此格式抛出异常IllegalArgumentException

*/

public static Date valueOf(String s) {

if (s == null) {

throw new java.lang.IllegalArgumentException();

}

final int YEAR_LENGTH = 4;//定义日期中年月日的长度及最大长度

final int MONTH_LENGTH = 2;

final int DAY_LENGTH = 2;

final int MAX_MONTH = 12;

final int MAX_DAY = 31;

Date d = null;

int firstDash = s.indexOf('-');//分隔年月日

int secondDash = s.indexOf('-', firstDash + 1);

int len = s.length();

if ((firstDash > 0) && (secondDash > 0) && (secondDash < len - 1)) {

if (firstDash == YEAR_LENGTH &&

(secondDash - firstDash > 1 && secondDash - firstDash <= MONTH_LENGTH + 1) &&

(len - secondDash > 1 && len - secondDash <= DAY_LENGTH + 1)) {

int year = Integer.parseInt(s, 0, firstDash, 10);//先转换为整数

int month = Integer.parseInt(s, firstDash + 1, secondDash, 10);

int day = Integer.parseInt(s, secondDash + 1, len, 10);

if ((month >= 1 && month <= MAX_MONTH) && (day >= 1 && day <= MAX_DAY)) {

d = new Date(year - 1900, month - 1, day);//转换为日期格式。

}

}

}

if (d == null) {

throw new java.lang.IllegalArgumentException();

}

return d;

}

/**

* Formats a date in the date escape format yyyy-mm-dd.

*

* @return a String in yyyy-mm-dd format

将日期型转换为yyyy-mm-dd格式的字符串

*/

@SuppressWarnings("deprecation")

public String toString () {

int year = super.getYear() + 1900;//java.util.Date的getYear()得到的日期为减掉1900的值,此处需要加上已获得真实事件

int month = super.getMonth() + 1;//同上

int day = super.getDate();

char buf[] = new char[10];//转为数值型在年月日中间加上横杠,再转为字符串

formatDecimalInt(year, buf, 0, 4);

buf[4] = '-';

Date.formatDecimalInt(month, buf, 5, 2);

buf[7] = '-';

Date.formatDecimalInt(day, buf, 8, 2);

return new String(buf);

}

/**

* Formats an unsigned integer into a char array in decimal output format.

* Numbers will be zero-padded or truncated if the string representation

* of the integer is smaller than or exceeds len, respectively.

*

* Should consider moving this to Integer and expose it through

* JavaLangAccess similar to Integer::formatUnsignedInt

* @param val  Value to convert

* @param buf  Array containing converted value

* @param offset Starting pos in buf

* @param len  length of output value

将无符号整型值val放到字符数组buf中,位数不足时补零,超出时截断

*/

static void formatDecimalInt(int val, char[] buf, int offset, int len) {//buf是数组行,形参值改变,实参值也改变(基本类型或者String,实参值不变,因为传的是值,对象集合数组传的是引用,实参值会变。)

int charPos = offset + len;

do {

buf[--charPos] = (char)('0' + (val % 10));//从最后一位开始取余数,转为字符放到字符数组中,如2019,则buf[3]=9再buf[2]=1...

val /= 10;

} while (charPos > offset);

}

// 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

永远抛出异常,不能使用。java.sql.Date值没有时间部分。弃用

*/

@Deprecated(since="1.2")

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

永远抛出异常,不能使用。java.sql.Date值没有时间部分。弃用

*/

@Deprecated(since="1.2")

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

永远抛出异常,不能使用。java.sql.Date值没有时间部分。弃用

*/

@Deprecated(since="1.2")

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

永远抛出异常,不能使用。java.sql.Date值没有时间部分。弃用

*/

@Deprecated(since="1.2")

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

永远抛出异常,不能使用。java.sql.Date值没有时间部分。弃用

*/

@Deprecated(since="1.2")

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

永远抛出异常,不能使用。java.sql.Date值没有时间部分。弃用

*/

@Deprecated(since="1.2")

public void setSeconds(int i) {

throw new java.lang.IllegalArgumentException();

}

/**

* Private serial version unique ID to ensure serialization

* compatibility.

*/

static final long serialVersionUID = 1511598038487230103L;

/**

* Obtains an instance of {@code Date} from a {@link LocalDate} object

* with the same year, month and day of month value as the given

* {@code LocalDate}.

*

* The provided {@code LocalDate} is interpreted as the local date

* in the local time zone.

*

* @param date a {@code LocalDate} to convert

* @return a {@code Date} object

* @exception NullPointerException if {@code date} is null

* @since 1.8

LocalDate型转换为Date型,弃用

*/

@SuppressWarnings("deprecation")

public static Date valueOf(LocalDate date) {

return new Date(date.getYear() - 1900, date.getMonthValue() -1,

date.getDayOfMonth());

}

/**

* Creates a {@code LocalDate} instance using the year, month and day

* from this {@code Date} object.

* @return a {@code LocalDate} object representing the same date value

*

* @since 1.8

Date型转为LocalDate型,弃用

*/

@SuppressWarnings("deprecation")

public LocalDate toLocalDate() {

return LocalDate.of(getYear() + 1900, getMonth() + 1, getDate());

}

/**

* This method always throws an UnsupportedOperationException and should

* not be used because SQL {@code Date} values do not have a time

* component.

*

* @exception java.lang.UnsupportedOperationException if this method is invoked

永远抛出异常,java.sql.Date值没有时间部分。

*/

@Override

public Instant toInstant() {

throw new java.lang.UnsupportedOperationException();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本系统的研发具有重大的意义,在安全性方面,用户使用浏览器访问网站时,采用注册和密码等相关的保护措施,提高系统的可靠性,维护用户的个人信息和财产的安全。在方便性方面,促进了校园失物招领网站的信息化建设,极大的方便了相关的工作人员对校园失物招领网站信息进行管理。 本系统主要通过使用Java语言编码设计系统功能,MySQL数据库管理数据,AJAX技术设计简洁的、友好的网址页面,然后在IDEA开发平台中,编写相关的Java代码文件,接着通过连接语言完成与数据库的搭建工作,再通过平台提供的Tomcat插件完成信息的交互,最后在浏览器中打开系统网址便可使用本系统。本系统的使用角色可以被分为用户和管理员,用户具有注册、查看信息、留言信息等功能,管理员具有修改用户信息,发布寻物启事等功能。 管理员可以选择任一浏览器打开网址,输入信息无误后,以管理员的身份行使相关的管理权限。管理员可以通过选择失物招领管理,管理相关的失物招领信息记录,比如进行查看失物招领信息标题,修改失物招领信息来源等操作。管理员可以通过选择公告管理,管理相关的公告信息记录,比如进行查看公告详情,删除错误的公告信息,发布公告等操作。管理员可以通过选择公告型管理,管理相关的公告型信息,比如查看所有公告型,删除无用公告型,修改公告型,添加公告型等操作。寻物启事管理页面,此页面提供给管理员的功能有:新增寻物启事,修改寻物启事,删除寻物启事。物品型管理页面,此页面提供给管理员的功能有:新增物品型,修改物品型,删除物品型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值