时间
来源:互联网 发布:asp手机版网站源码 编辑:程序博客网 时间:2024/05/19 06:38
public class GetDate {
public GetDate(){}
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
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 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(java.util.Date dateDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
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()-3600000*34*day;
Date date_3_hm_date=new Date(date_3_hm);
return date_3_hm_date;
}
}
2.
public GetDate(){}
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
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 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(java.util.Date dateDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
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()-3600000*34*day;
Date date_3_hm_date=new Date(date_3_hm);
return date_3_hm_date;
}
}
2.
- mport java.util.Calendar;
- import java.util.Date;
- import java.text.*;
- public class DateDealWith
- {
- public DateDealWith(){
- }
- //取得系统当前时间,格式为yyyy-mm-dd
- public String getCurrentDate(){
- Calendar rightNow = Calendar.getInstance();
- int year=rightNow.get(rightNow.YEAR);
- int month=rightNow.get(rightNow.MONTH)+1;
- int day=rightNow.get(rightNow.DATE);
- return year+"-"+month+"-"+day;
- }
- //取得系统当前时间,格式为yyyy年mm月dd日
- public String getCurrentDate1(){
- Calendar rightNow = Calendar.getInstance();
- int year=rightNow.get(rightNow.YEAR);
- int month=rightNow.get(rightNow.MONTH)+1;
- int day=rightNow.get(rightNow.DATE);
- return year+"年"+month+"月"+day+"日";
- }
- //取得系统当前时间前n个月的相对应的一天
- public String getNMonthBeforeCurrentDay(int n){
- Calendar c = Calendar.getInstance();
- c.add(c.MONTH,-n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //取得系统当前时间后n个月的相对应的一天
- public String getNMonthAfterCurrentDay(int n){
- Calendar c = Calendar.getInstance();
- c.add(c.MONTH,n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //取得系统当前时间前n天,格式为yyyy-mm-dd
- public String getNDayBeforeCurrentDate(int n){
- Calendar c = Calendar.getInstance();
- c.add(c.DAY_OF_MONTH,-n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //取得系统当前时间后n天,格式为yyyy-mm-dd
- public String getNDayAfterCurrentDate(int n){
- Calendar c = Calendar.getInstance();
- c.add(c.DAY_OF_MONTH,n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //---------------------------------------------------------------------
- //取过去一个时间对应的系统当年的一天
- public String getCurrentDateAfterPastDate(String sPastDate){
- if(sPastDate!=null && !sPastDate.equals("")){
- Date date=switchStringToDate(sPastDate);
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- int iPastYear=c.get(c.YEAR);
- Calendar c1 = Calendar.getInstance();
- int iCurrentYear=c1.get(c1.YEAR);
- c.add(c.YEAR,iCurrentYear-iPastYear);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }else{
- return null;
- }
- }
- //-----------------------------------------------------------------
- //将一个日期字符串转化成日期
- public Date switchStringToDate(String sDate){
- Date date=null;
- try{
- SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
- date=df.parse(sDate);
- }catch(Exception e){
- System.out.println("日期转换失败:"+e.getMessage());
- }
- return date;
- }
- //输入两个字符串型的日期,比较两者的大小
- public boolean compareTwoDateBigOrSmall(String fromDate,String toDate){
- Date dateFrom = this.switchStringToDate(fromDate);
- Date dateTo = this.switchStringToDate(toDate);
- if(dateFrom.before(dateTo)){
- return true;
- }else{
- return false;
- }
- }
- //将一个日期字符串转化成Calendar
- public Calendar switchStringToCalendar(String sDate){
- Date date = switchStringToDate(sDate);
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- return c;
- }
- //将一个日期转化成Calendar
- public Calendar switchStringToCalendar(Date date){
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- return c;
- }
- //------------------------------------------------------------------------
- //取得某个时间前n个月的相对应的一天
- public String getNMonthBeforeOneDay(String sDate,int n){
- Calendar c = switchStringToCalendar(sDate);
- c.add(c.MONTH,-n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //取得某个时间后n个月的相对应的一天
- public String getNMonthAfterOneDay(String sDate,int n){
- Calendar c = switchStringToCalendar(sDate);
- c.add(c.MONTH,n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //取得某个时间前n天,格式为yyyy-mm-dd
- public String getNDayBeforeOneDate(String sDate,int n){
- Calendar c = switchStringToCalendar(sDate);
- c.add(c.DAY_OF_MONTH,-n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //取得某个时间后n天,格式为yyyy-mm-dd
- public String getNDayAfterOneDate(String sDate,int n){
- Calendar c = switchStringToCalendar(sDate);
- c.add(c.DAY_OF_MONTH,n);
- return ""+c.get(c.YEAR)+"-"+(c.get(c.MONTH)+1)+"-"+c.get(c.DATE);
- }
- //判断系统当前时间是不是润年
- public boolean isRunNian(){
- java.util.Calendar rightNow = java.util.Calendar.getInstance();
- int year=rightNow.get(rightNow.YEAR);
- if(0==year%4 && (year%100!=0 || year%400==0)){
- return true;
- }else{
- return false;
- }
- }
- }
- 【时间】
- 时间!!
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- 时间
- C++引用与指针的比较
- svn在flex3或eclipse3中的配置
- 为什么需要TLS(Thread Local Storage)?
- 向DropDownList插入数据
- C#学习笔记(十六):使用打开保存文件对话框
- 时间
- 一个比较好的文件操作的例子
- MegaCli 常见用法
- suse enterprise 10 上的XEN 很VM的感觉
- 统驭科目(http://baike.baidu.com/view/940049.htm#)
- javascript隐藏或则删除控件的两种方法
- C#实现图片到数据库的存取
- 面向对象编程 和 面向接口编程
- 你的代码真的很健壮吗