`
yyyyy5101
  • 浏览: 149013 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

java 日期处理

阅读更多
一。
  Date 比较:
     Date a; Date b;
      1.
          a.after(b);返回boolean a在b后返回true  
          a.before(b);返回boolean b在a前返回true  
          a.equals(b); a,b相等返回true
      2.
          Calendar c1 = Calendar.getInstance();
  c1.setTime(a);
  Calendar c2 = Calendar.getInstance();
  c2.setTime(b);
          a.compareTo(b) ; 返回int, 大于0,a在b后; 小于0,a在b前;等于0,a=b
 
二。
  Date转化字符串
      Date a;
      String startDate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(d1);
      月份的MM要大写的,分钟的mm一定要小写的   HH  表示24进制的; hh 表示12进制的

三。
  字符串转化Date
      String s = "2010-05-07 14:04:32";
      DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      try{
           Date d = format.parse(s);
      }catch(Exception e){

      }finnally{

      }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics