時間字符串轉換

None.gif try
ExpandedBlockStart.gifContractedBlock.gif     
dot.gif
InBlock.gif      String st
="2005-13-32 12:00";
InBlock.gif     java.text.DateFormat df 
= new SimpleDateFormat("yyyy-MM-dd hh:mm");
InBlock.gif              Date  starttime 
= df.parse(st);
InBlock.gif     System.out.println(starttime.toString());        
ExpandedBlockEnd.gif     }
 
None.gif
catch (Exception ex)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif 
ExpandedBlockEnd.gif}

None.gif

ExpandedBlockStart.gif ContractedBlock.gif try   dot.gif {
InBlock.gif   String st 
= "2005-12-2 12:00:00";
InBlock.gif   Timestamp starttime 
= Timestamp.valueOf(st);
InBlock.gif   System.out.println(starttime.toString());
ExpandedBlockStart.gifContractedBlock.gif  }
  catch  (Exception ex)  dot.gif {
InBlock.gif   ex.printStackTrace();
ExpandedBlockEnd.gif  }

None.gif


None.gif import  java.sql. * ;
None.gif
import  java.util. * ;
ExpandedBlockStart.gifContractedBlock.gif
public   class  CreateTimestamp  dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif   
public static void main(String [] args) dot.gif{
InBlock.gif   Calendar cal 
= Calendar.getInstance();
InBlock.gif   cal.set(Calendar.YEAR, 
2000);
InBlock.gif   cal.set(Calendar.MONTH, Calendar.JANUARY);
InBlock.gif   cal.set(Calendar.DATE, 
1);
InBlock.gif   cal.set(Calendar.HOUR_OF_DAY, 
11);
InBlock.gif   cal.set(Calendar.MINUTE, 
45);
InBlock.gif   cal.set(Calendar.SECOND, 
30);
InBlock.gif   cal.set(Calendar.MILLISECOND, 
0);
InBlock.gif   
long millis = cal.getTime().getTime();
InBlock.gif   System.out.println(
"milliseconds in millis = " + millis);
InBlock.gif   java.sql.Timestamp ts 
= new java.sql.Timestamp(millis);
InBlock.gif   System.out.println(
"Timestamp ts before setting nanos = " + ts);
InBlock.gif   ts.setNanos(
500);
InBlock.gif   System.out.println(
"Timestamp ts with nanos set = " + ts);
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif
posted on 2006-12-13 14:35 waya 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/waya/archive/2006/12/13/590924.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值