日期格式变化

查询出某天的记录的方法:

select t.* from order1 t where  to_char(t.time1,'yyyy-MM-dd')= '2009-12-01'

import java.text.SimpleDateFormat;

 import java.text.ParseException;

 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");    

Date dealDate=null;

try{

dealDate=sdf.parse(dealHoldingBondVo.getDealDate());//字符串变日期

   }

   catch (ParseException e){

       e.printStackTrace();

Notification.show("日期格式不对,请检查Excel后重新上传.",Type.ERROR_MESSAGE);

   }

把今天的日期转成字符串可用 String str = sdf.format(new Date()); 

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
   String str = format.format(date); 

  1. Date d = new Date();  
  2.         SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制  
  3.         System.out.println(ss.format(d));  
  4.   
  5.         Date date = new Date();  
  6.         SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制  
  7.         String LgTime = sdformat.format(date);  
  8.         System.out.println(LgTime);  
  9.   
  10.   
  11. 结果为  
  12. 2008-05-28 01:32:54  
  13. 2008-05-28 13:32:54  
  1. Date类,已经很少用了。更多使用的是Calendar   
      Calendar
        date    =    Calendar.getInstance();   
      date.get(Calendar.HOUR_OF_DAY    );//得到24小时机制的   
      date.get(Calendar.HOUR);//    得到12小时机制的   

猜你喜欢

转载自oylx.iteye.com/blog/2318065