1.java内部的数据类型转换
1.1:简单类型 boolean byte char short int long float double void
封装器类 Boolean Byte Character Short Integer Long Float Double Void
1.2:byte=short=>int=>long=>float=>double
char=>int
byte、short、char是同级的无法自动转换。
1.3:日期
1.3.1:Date(int year, int month, int date, int hrs, int min, int sec):以int型表示年、月、日、时、分、秒
1.3.2:Date(long date)。1970年1月1日0时0分0秒的毫秒数。
1.3.3:SimpleDateFormat sd=new SimpleDateFormat("dd"); String syear=sy.format(date);
1.3.4:java.util.Calendar——抽象类,通过Calendar.getInstance();获得对象。
1.3.4.1:set(int field,int value)——设置字段时间、add(int field,int amount)——指定字段的当前时间上修改时间
和 roll(int field,boolean down)——在给定的时间字段上添加(false)或减去(上/下)单个时间单元,不更改更大的字段。
1.3.4.2:clear、after、before、isLenient、isSet
*当字节类型变量参与运算,java作自动数据运算类型的提升,将其转换为int类型。
*带小数的变量默认为double类型
*
*
*
*
*
2.java与SQL的数据类型转换
2.1:java.sql.Date——一个包装了毫秒值的瘦包装器 (thin wrapper),它允许 JDBC 将毫秒值标识为 SQL DATE
值。
2.1.1:new Date(long date)=setTime(long)date
2.1.2:String—date【toString()<——>valueOf()】
2.2:java.sql.Time——与 java.util.Date
类有关的瘦包装器 (thin wrapper),它允许 JDBC 将该类标识为 SQL TIME
值。Time
类添加格式化和解析操作以支持时间值的 JDBC 转义语法。
2.3:java.sql.Timestamp——它允许 JDBC API 将该类标识为 SQL TIMESTAMP
值。它通过允许小数秒到纳秒级精度的规范来添加保存 SQL TIMESTAMP
小数秒值的能力。Timestamp 也提供支持时间戳值的 JDBC 转义语法的格式化和解析操作的能力。