`
zengbin163
  • 浏览: 13642 次
  • 性别: Icon_minigender_1
  • 来自: 南昌
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Date和Srting转化

 
阅读更多
package com.jxhaina.warehouse.util;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetDate {

public GetDate(){

}

    public static Date getNowDate()
    {
        Date currentTime = new Date();
        return currentTime;
    }

    public static void main(String arg[]){
   
    System.out.println(strToBirthday("2003-12-01"));
   
    }

    public static String getStringDate()
    {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String getStringDateShort()
    {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(currentTime);
        return dateString;
    }
   
    public static String getDateString(){
   
    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyMdHms");
        String strTime = simpledateformat.format(new Date());
        return strTime;
   
    }
    public static String dateToStrl(Date dateDate){
    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyMdHms");
    String strTime = simpledateformat.format(dateDate);
        return strTime;
    }

    public static Date strToDate(String strDate)
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static String dateToStr(Date dateDate)
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(dateDate);
        return dateString;
    }
   
    public static String dateToStrSh(Date dateDate)
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    public static Date strToBirthday(String strDate)
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }

    public static Date getNow()
    {
        Date currentTime = new Date();
        return currentTime;
    }

    public static long getS(String strDate)
    {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate.getTime();
    }

    public static Date getLastDate(long day)
    {
        Date date = new Date();
        long date_3_hm = date.getTime() - 0x74bad00L * day;
        Date date_3_hm_date = new Date(date_3_hm);
        return date_3_hm_date;
    }

    public static int getNowDay(String StrDate)
    {
        Date Time1 = strToDate(StrDate);
        Date Time2 = new Date();
        long day = Time1.getTime() - Time2.getTime();
        return (int)day / 0x5265c00;
    }

    public static int getNowDay(Date StrDate)
    {
        Date Time1 = StrDate;
        Date Time2 = new Date();
        long day = Time1.getTime() - Time2.getTime();
        return (int)day / 0x5265c00;
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics