日期格式的轉換以及資料庫的日期格式

2021-09-01 19:09:25 字數 2388 閱讀 2127

******dateformat sdformat =new******dateformat("yyyy-mm-dd hh:mm:ss");//24小時制

******dateformat ss =new******dateformat("yyyy-mm-dd hh:mm:ss");//12小時制

獲取明天:

date date=new date();

calendar calendar = new gregoriancalendar();

calendar.settime(date);

calendar.add(calendar.date,1);//把日期往後增加一天.整數往後推,負數往前移動

date=calendar.gettime(); //這個時間就是日期往後推一天的結果------ 獲取明天

******dateformat formatter = new ******dateformat("yyyy-mm-dd");

string datestring = formatter.format(date);

字串轉換為日期 :

date d =newdate();

string today=

sdformat

.format(d);

today=today.substring(0,today.lastindexof(

" "))+

" 00:00:00"

;date td=df.parse(today);

資料庫中日期轉換:

to_char(date,』 'yyyy-mm-dd hh12:mi:ss』)   2013-12-12 12:12:15//12小時制

to_char(date,』 'yyyy-mm-dd hh24:mi:ss』)   2013-12-12 14:12:15//24小時制

其他:1》以12小時制顯示 

sql>select to_char(sysdate,'yyyy-mm-dd hh12:mi:ss am')from dual; 

to_char(sysdate,'yyyy-mm-ddhh1 

------------------------------ 

2007-06-29 02:50:06 下午 

2》以24小時制顯示 

sql> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss am')from dual; 

to_char(sysdate,'yyyy-mm-ddhh2 

----------------------------- 

2007-06-29 15:00:58 下午 

3》得到當前時間的前一分鐘 

select to_char(sysdate-1/21/60,'hh24:mi:ss')from dual; 

to_char(sysdate-1/21/60,'hh24: 

------------------------------ 

15:00:54 

4》得到當前時間的後一分鐘 

select to_char(sysdate+1/21/60,'hh24:mi:ss')from dual; 

to_char(sysdate+1/21/60,'hh24: 

------------------------------ 

15:03:53 

5》得到當前時間的前一小時 

select to_char(sysdate-1/24,'hh24:mi:ss')from dual; 

to_char(sysdate-1/24,'hh24:mi: 

------------------------------ 

14:03:13 

6》得到當前時間的後一小時 

select to_char(sysdate+1/24,'hh24:mi:ss')from dual; 

to_char(sysdate+1/24,'hh24:mi: 

------------------------------ 

7》得到當前時間的後一天 

select to_char(sysdate+1,'yyyy-mm-dd')from dual; 

to_char(sysdate+1,'yyyy-mm-dd'

to_date('2004-11-27 13:34:43', yyyy-mm-dd hh24 :mi:ss')

將字元型轉換成日期格式

to_char():

將日期轉按一定格式換成字元型別 

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') time from dual;

資料庫中的日期格式

db2 select timestamp 2010 06 01 00 00 00.000 from table select date 2010 06 01 00 00 00 from table date函式 語法 date arg date函式返回乙個日期 時間戳 日期字串 時間戳字串中的日期。...

日期格式的轉換

public class demo 這是整理了乙個時間物件和字串相互轉換的乙個小工具類 public class dateutils 日期轉換成字串,引數為日期和格式 public static string datetostring date d,string fromat 字串轉換成日期,引數為...

格式化資料庫日期

格式化資料庫日期。此 段將允許您輸入date引數。它將檢查date引數以檢視是否存在有效的時間部分。然後,它將格式化日期,使其無論在何處或如何使用都可以正常工作。public function formatdate byval vdtdate as date as string dim dtnull...