timestamp java sql_java.sql.Timestamp类型

如果想向数据库中插入日期时间的话,可以用java.sql.Timestamp类

一个与 java.util.Date类有关的瘦包装器 (thin wrapper),它允许 JDBC API 将该类标识为 SQL TIMESTAMP值。它通过允许小数秒到纳秒级精度的规范来添加保存 SQL TIMESTAMP小数秒值的能力。Timestamp 也提供支持时间戳值的 JDBC 转义语法的格式化解析操作的能力。

计算 Timestamp 对象的精度为二者之一:

19 ,其为 yyyy-mm-dd hh:mm:ss 格式下的字符数

20 + s ,其为 yyyy-mm-dd hh:mm:ss.[fff...] 格式下的字符数,

s表示给定 Timestamp 的标度(其小数秒精度)。

注:此类型由 java.util.Date和单独的毫微秒值组成。只有整数秒才会存储在 java.util.Date组件中。小数秒(毫微秒)是独立存在的。传递不是 java.sql.Timestamp实例的对象时,Timestamp.equals(Object)方法永远不会返回 true,因为日期的毫微秒组件是未知的,相对于 java.util.Date.equals(Object)方法而言,Timestamp.equals(Object)方法是不对称的。此外,hashcode方法使用底层java.util.Date

实现并因此在其计算中不包括毫微秒。 鉴于 Timestamp类和上述 java.util.Date类之间的不同,建议代码一般不要将 Timestamp值为 java.util.Date的实例。Timestamp和 java.util.Date之间的继承关系实际上指的是实现继承,而不是类型继承。

===================================================================================

1.Timestamp 与String类型相互转换

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式

Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间

String str = df.format(now);

---------

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String time = df.format(new Date());

Timestamp ts = Timestamp.valueOf(time);

2.java.sql.Date与java.sql.Timestamp相互转换

java.sql.Date--->java.sql.Timestamp

new java.sql.Timestamp(yourDate.getTime());

java.sql.Timestamp-->java.sql.Date

new java.sql.Date(yourTimestamp.getTime());

转自:http://blog.163.com/dingyi_57@126/blog/static/11047919520107253563968/

insert overwrite table discountdw.dwd_sd_adds_order_bill_inc partition(dt = '2023-06-06') select t1.order_bill_id, t1.counterfoil_no, t1.acceptor, date_format(to_utc_timestamp(cast(t1.expiry_date as bigint) ,'GMT-8'),'YYYY-MM-dd'), t2.company_id, t1.cert_no, t1.company_name, t1.third_order_id, t1.counterfoil_amt/10000, t1.transaction_amt/10000, t1.rate, '3bp' as service_tariffing, ((DATEDIFF(to_utc_timestamp(t1.expiry_date ,'GMT-8'),to_utc_timestamp(t1.transaction_date ,'GMT-8') ) + adjust_days)* 0.0003 *(counterfoil_amt))/ 360 as service_fee, 360 as total_days, DATEDIFF(to_utc_timestamp(t1.expiry_date ,'GMT-8'),to_utc_timestamp(t1.transaction_date ,'GMT-8') ) + adjust_days as modulation_date, t3.channel_type, t3.bank_name, date_format(to_utc_timestamp(cast(t1.transaction_date as bigint) ,'GMT-8'),'YYYY-MM-dd'), t1.order_status_code, t1.order_status_msg, t4.fee_amt, t4.status, t1.tenant_id, t5.revenue, to_utc_timestamp(cast(t1.create_date as bigint) ,'GMT-8'), to_utc_timestamp(cast(t1.update_date as bigint) ,'GMT-8') from (select * from discountdw.ods_adds_order_bill_inc where dt ='2023-06-06' and channel_id=101110004 )t1 left join (select * from mecdw.ods_company_full where platform_id='sdpjw')t2 on t1.cert_no=t2.cert_no and t1.tenant_id=t2.tenant_id left join discountdw.dim_adds_product_full t3 on t1.partner_id=t3.partner_id and t1.product_id=t3.product_id left join (select * from mecdw.dwd_sc_fee_record_full where dt='2023-06-06' and biz_type=2 ) t4 on t1.order_bill_id=t4.third_id left join (select * from discountdw.ods_sd_order_ext_inc where dt='2023-06-06') t5 on t1.order_bill_id=t5.order_bill_id left join sdpjwdw.dim_holiday_info_full t6 on date_format(to_utc_timestamp(t1.expiry_date ,'GMT-8'),'YYYY-MM-dd') = t6.civic_holiday ;
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值