`
liyonghui160com
  • 浏览: 782408 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Java时间格式转换大全

    博客分类:
  • java
 
阅读更多

 

Java时间格式转换大全

import java.text.*;
import java.util.Calendar;
public class VeDate {
/**
   * 获取现在时间
   * 
   * @return 返回时间类型 yyyy-MM-dd HH:mm:ss
   */
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;
}
/**
   * 获取现在时间
   * 
   * @return返回短时间格式 yyyy-MM-dd
   */
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");         
DateFormat format 2= new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");         
Date date = null;    
String str = null;                  
            
// String转Date    
str = "2007-1-18";          
try {    
           date = format1.parse(str);   
           data = format2.parse(str); 
} catch (ParseException e) {    
           e.printStackTrace();    
}   
/**
   * 获取现在时间
   * 
   * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
   */
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;
}
/**
   * 获取现在时间
   * 
   * @return 返回短时间字符串格式yyyy-MM-dd
   */
public static String getStringDateShort() {
   Date currentTime = new Date();
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
   String dateString = formatter.format(currentTime);
   return dateString;
}
/**
   * 获取时间 小时:分;秒 HH:mm:ss
   * 
   * @return
   */
public static String getTimeShort() {
   SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
   Date currentTime = new Date();
   String dateString = formatter.format(currentTime);
   return dateString;
}
/**
   * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
   * 
   * @param strDate
   * @return
   */
public static Date strToDateLong(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;
}
/**
   * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
   * 
   * @param dateDate
   * @return
   */
public static String dateToStrLong(java.util.Date dateDate) {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   String dateString = formatter.format(dateDate);
   return dateString;
}
/**
   * 将短时间格式时间转换为字符串 yyyy-MM-dd
   * 
   * @param dateDate
   * @param k
   * @return
   */
public static String dateToStr(java.util.Date dateDate) {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
   String dateString = formatter.format(dateDate);
   return dateString;
}
/**
   * 将短时间格式字符串转换为时间 yyyy-MM-dd 
   * 
   * @param strDate
   * @return
   */
public static Date strToDate(String strDate) {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
   ParsePosition pos = new ParsePosition(0);
   Date strtodate = formatter.parse(strDate, pos);
   return strtodate;
}
/**
   * 得到现在时间
   * 
   * @return
   */
public static Date getNow() {
   Date currentTime = new Date();
   return currentTime;
}
/**
   * 提取一个月中的最后一天
   * 
   * @param day
   * @return
   */
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;
}
/**
   * 得到现在时间
   * 
   * @return 字符串 yyyyMMdd HHmmss
   */
public static String getStringToday() {
   Date currentTime = new Date();
   SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
   String dateString = formatter.format(currentTime);
   return dateString;
}
/**
   * 得到现在小时
   */
public static String getHour() {
   Date currentTime = new Date();
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   String dateString = formatter.format(currentTime);
   String hour;
   hour = dateString.substring(11, 13);
   return hour;
}
/**
   * 得到现在分钟
   * 
   * @return
   */
public static String getTime() {
   Date currentTime = new Date();
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   String dateString = formatter.format(currentTime);
   String min;
   min = dateString.substring(14, 16);
   return min;
}
/**
   * 根据用户传入的时间表示格式,返回当前时间的格式 如果是yyyyMMdd,注意字母y不能大写。
   * 
   * @param sformat
   *             yyyyMMddhhmmss
   * @return
   */
public static String getUserDate(String sformat) {
   Date currentTime = new Date();
   SimpleDateFormat formatter = new SimpleDateFormat(sformat);
   String dateString = formatter.format(currentTime);
   return dateString;
}

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

做成方法

 

import java.util.*;
import java.text.*;
import java.util.Calendar;

public class VeDate {
 /**
  * 获取现在时间
  * 
  * @return 返回时间类型 yyyy-MM-dd HH:mm:ss
  */
 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;
 }

 /**
  * 获取现在时间
  * 
  * @return返回短时间格式 yyyy-MM-dd
  */
 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;
 }

 /**
  * 获取现在时间
  * 
  * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
  */
 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;
 }

 /**
  * 获取现在时间
  * 
  * @return 返回短时间字符串格式yyyy-MM-dd
  */
 public static String getStringDateShort() {
  Date currentTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  String dateString = formatter.format(currentTime);
  return dateString;
 }

 /**
  * 获取时间 小时:分;秒 HH:mm:ss
  * 
  * @return
  */
 public static String getTimeShort() {
  SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
  Date currentTime = new Date();
  String dateString = formatter.format(currentTime);
  return dateString;
 }

 /**
  * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
  * 
  * @param strDate
  * @return
  */
 public static Date strToDateLong(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;
 }

 /**
  * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
  * 
  * @param dateDate
  * @return
  */
 public static String dateToStrLong(java.util.Date dateDate) {
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  String dateString = formatter.format(dateDate);
  return dateString;
 }

 /**
  * 将短时间格式时间转换为字符串 yyyy-MM-dd
  * 
  * @param dateDate
  * @param k
  * @return
  */
 public static String dateToStr(java.util.Date dateDate) {
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  String dateString = formatter.format(dateDate);
  return dateString;
 }

 /**
  * 将短时间格式字符串转换为时间 yyyy-MM-dd 
  * 
  * @param strDate
  * @return
  */
 public static Date strToDate(String strDate) {
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  ParsePosition pos = new ParsePosition(0);
  Date strtodate = formatter.parse(strDate, pos);
  return strtodate;
 }

 /**
  * 得到现在时间
  * 
  * @return
  */
 public static Date getNow() {
  Date currentTime = new Date();
  return currentTime;
 }

 /**
  * 提取一个月中的最后一天
  * 
  * @param day
  * @return
  */
 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;
 }

 /**
  * 得到现在时间
  * 
  * @return 字符串 yyyyMMdd HHmmss
  */
 public static String getStringToday() {
  Date currentTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
  String dateString = formatter.format(currentTime);
  return dateString;
 }

 /**
  * 得到现在小时
  */
 public static String getHour() {
  Date currentTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  String dateString = formatter.format(currentTime);
  String hour;
  hour = dateString.substring(11, 13);
  return hour;
 }

 /**
  * 得到现在分钟
  * 
  * @return
  */
 public static String getTime() {
  Date currentTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  String dateString = formatter.format(currentTime);
  String min;
  min = dateString.substring(14, 16);
  return min;
 }

 /**
  * 根据用户传入的时间表示格式,返回当前时间的格式 如果是yyyyMMdd,注意字母y不能大写。
  * 
  * @param sformat
  *            yyyyMMddhhmmss
  * @return
  */
 public static String getUserDate(String sformat) {
  Date currentTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat(sformat);
  String dateString = formatter.format(currentTime);
  return dateString;
 }

 /**
  * 二个小时时间间的差值,必须保证二个时间都是"HH:MM"的格式,返回字符型的分钟
  */
 public static String getTwoHour(String st1, String st2) {
  String[] kk = null;
  String[] jj = null;
  kk = st1.split(":");
  jj = st2.split(":");
  if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0]))
   return "0";
  else {
   double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) / 60;
   double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) / 60;
   if ((y - u) > 0)
    return y - u + "";
   else
    return "0";
  }
 }

 /**
  * 得到二个日期间的间隔天数
  */
 public static String getTwoDay(String sj1, String sj2) {
  SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
  long day = 0;
  try {
   java.util.Date date = myFormatter.parse(sj1);
   java.util.Date mydate = myFormatter.parse(sj2);
   day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
  } catch (Exception e) {
   return "";
  }
  return day + "";
 }

 /**
  * 时间前推或后推分钟,其中JJ表示分钟.
  */
 public static String getPreTime(String sj1, String jj) {
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  String mydate1 = "";
  try {
   Date date1 = format.parse(sj1);
   long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
   date1.setTime(Time * 1000);
   mydate1 = format.format(date1);
  } catch (Exception e) {
  }
  return mydate1;
 }

 /**
  * 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
  */
 public static String getNextDay(String nowdate, String delay) {
  try{
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  String mdate = "";
  Date d = strToDate(nowdate);
  long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60;
  d.setTime(myTime * 1000);
  mdate = format.format(d);
  return mdate;
  }catch(Exception e){
   return "";
  }
 }

 /**
  * 判断是否润年
  * 
  * @param ddate
  * @return
  */
 public static boolean isLeapYear(String ddate) {

  /**
   * 详细设计: 1.被400整除是闰年,否则: 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年
   * 3.能被4整除同时能被100整除则不是闰年
   */
  Date d = strToDate(ddate);
  GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
  gc.setTime(d);
  int year = gc.get(Calendar.YEAR);
  if ((year % 400) == 0)
   return true;
  else if ((year % 4) == 0) {
   if ((year % 100) == 0)
    return false;
   else
    return true;
  } else
   return false;
 }

 /**
  * 返回美国时间格式 26 Apr 2006
  * 
  * @param str
  * @return
  */
 public static String getEDate(String str) {
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  ParsePosition pos = new ParsePosition(0);
  Date strtodate = formatter.parse(str, pos);
  String j = strtodate.toString();
  String[] k = j.split(" ");
  return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
 }

 /**
  * 获取一个月的最后一天
  * 
  * @param dat
  * @return
  */
 public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd
  String str = dat.substring(0, 8);
  String month = dat.substring(5, 7);
  int mon = Integer.parseInt(month);
  if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) {
   str += "31";
  } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
   str += "30";
  } else {
   if (isLeapYear(dat)) {
    str += "29";
   } else {
    str += "28";
   }
  }
  return str;
 }

 /**
  * 判断二个时间是否在同一个周
  * 
  * @param date1
  * @param date2
  * @return
  */
 public static boolean isSameWeekDates(Date date1, Date date2) {
  Calendar cal1 = Calendar.getInstance();
  Calendar cal2 = Calendar.getInstance();
  cal1.setTime(date1);
  cal2.setTime(date2);
  int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
  if (0 == subYear) {
   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
    return true;
  } else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) {
   // 如果12月的最后一周横跨来年第一周的话则最后一周即算做来年的第一周
   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
    return true;
  } else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) {
   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
    return true;
  }
  return false;
 }

 /**
  * 产生周序列,即得到当前时间所在的年度是第几周
  * 
  * @return
  */
 public static String getSeqWeek() {
  Calendar c = Calendar.getInstance(Locale.CHINA);
  String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR));
  if (week.length() == 1)
   week = "0" + week;
  String year = Integer.toString(c.get(Calendar.YEAR));
  return year + week;
 }

 /**
  * 获得一个日期所在的周的星期几的日期,如要找出2002年2月3日所在周的星期一是几号
  * 
  * @param sdate
  * @param num
  * @return
  */
 public static String getWeek(String sdate, String num) {
  // 再转换为时间
  Date dd = VeDate.strToDate(sdate);
  Calendar c = Calendar.getInstance();
  c.setTime(dd);
  if (num.equals("1")) // 返回星期一所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  else if (num.equals("2")) // 返回星期二所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
  else if (num.equals("3")) // 返回星期三所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
  else if (num.equals("4")) // 返回星期四所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
  else if (num.equals("5")) // 返回星期五所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
  else if (num.equals("6")) // 返回星期六所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
  else if (num.equals("0")) // 返回星期日所在的日期
   c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
  return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
 }

 /**
  * 根据一个日期,返回是星期几的字符串
  * 
  * @param sdate
  * @return
  */
 public static String getWeek(String sdate) {
  // 再转换为时间
  Date date = VeDate.strToDate(sdate);
  Calendar c = Calendar.getInstance();
  c.setTime(date);
  // int hour=c.get(Calendar.DAY_OF_WEEK);
  // hour中存的就是星期几了,其范围 1~7
  // 1=星期日 7=星期六,其他类推
  return new SimpleDateFormat("EEEE").format(c.getTime());
 }
 public static String getWeekStr(String sdate){
  String str = "";
  str = VeDate.getWeek(sdate);
  if("1".equals(str)){
   str = "星期日";
  }else if("2".equals(str)){
   str = "星期一";
  }else if("3".equals(str)){
   str = "星期二";
  }else if("4".equals(str)){
   str = "星期三";
  }else if("5".equals(str)){
   str = "星期四";
  }else if("6".equals(str)){
   str = "星期五";
  }else if("7".equals(str)){
   str = "星期六";
  }
  return str;
 }

 /**
  * 两个时间之间的天数
  * 
  * @param date1
  * @param date2
  * @return
  */
 public static long getDays(String date1, String date2) {
  if (date1 == null || date1.equals(""))
   return 0;
  if (date2 == null || date2.equals(""))
   return 0;
  // 转换为标准时间
  SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
  java.util.Date date = null;
  java.util.Date mydate = null;
  try {
   date = myFormatter.parse(date1);
   mydate = myFormatter.parse(date2);
  } catch (Exception e) {
  }
  long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
  return day;
 }

 /**
  * 形成如下的日历 , 根据传入的一个时间返回一个结构 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是当月的各个时间
  * 此函数返回该日历第一行星期日所在的日期
  * 
  * @param sdate
  * @return
  */
 public static String getNowMonth(String sdate) {
  // 取该时间所在月的一号
  sdate = sdate.substring(0, 8) + "01";

  // 得到这个月的1号是星期几
  Date date = VeDate.strToDate(sdate);
  Calendar c = Calendar.getInstance();
  c.setTime(date);
  int u = c.get(Calendar.DAY_OF_WEEK);
  String newday = VeDate.getNextDay(sdate, (1 - u) + "");
  return newday;
 }

 /**
  * 取得数据库主键 生成格式为yyyymmddhhmmss+k位随机数
  * 
  * @param k
  *            表示是取几位随机数,可以自己定
  */

 public static String getNo(int k) {

  return getUserDate("yyyyMMddhhmmss") + getRandom(k);
 }

 /**
  * 返回一个随机数
  * 
  * @param i
  * @return
  */
 public static String getRandom(int i) {
  Random jjj = new Random();
  // int suiJiShu = jjj.nextInt(9);
  if (i == 0)
   return "";
  String jj = "";
  for (int k = 0; k < i; k++) {
   jj = jj + jjj.nextInt(9);
  }
  return jj;
 }

 /**
  * 
  * @param args
  */
 public static boolean RightDate(String date) {

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  ;
  if (date == null)
   return false;
  if (date.length() > 10) {
   sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  } else {
   sdf = new SimpleDateFormat("yyyy-MM-dd");
  }
  try {
   sdf.parse(date);
  } catch (ParseException pe) {
   return false;
  }
  return true;
 }

 /***************************************************************************
  * //nd=1表示返回的值中包含年度 //yf=1表示返回的值中包含月份 //rq=1表示返回的值中包含日期 //format表示返回的格式 1
  * 以年月日中文返回 2 以横线-返回 // 3 以斜线/返回 4 以缩写不带其它符号形式返回 // 5 以点号.返回
  **************************************************************************/
 public static String getStringDateMonth(String sdate, String nd, String yf, String rq, String format) {
  Date currentTime = new Date();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  String dateString = formatter.format(currentTime);
  String s_nd = dateString.substring(0, 4); // 年份
  String s_yf = dateString.substring(5, 7); // 月份
  String s_rq = dateString.substring(8, 10); // 日期
  String sreturn = "";
  roc.util.MyChar mc = new roc.util.MyChar();
  if (sdate == null || sdate.equals("") || !mc.Isdate(sdate)) { // 处理空值情况
   if (nd.equals("1")) {
    sreturn = s_nd;
    // 处理间隔符
    if (format.equals("1"))
     sreturn = sreturn + "年";
    else if (format.equals("2"))
     sreturn = sreturn + "-";
    else if (format.equals("3"))
     sreturn = sreturn + "/";
    else if (format.equals("5"))
     sreturn = sreturn + ".";
   }
   // 处理月份
   if (yf.equals("1")) {
    sreturn = sreturn + s_yf;
    if (format.equals("1"))
     sreturn = sreturn + "月";
    else if (format.equals("2"))
     sreturn = sreturn + "-";
    else if (format.equals("3"))
     sreturn = sreturn + "/";
    else if (format.equals("5"))
     sreturn = sreturn + ".";
   }
   // 处理日期
   if (rq.equals("1")) {
    sreturn = sreturn + s_rq;
    if (format.equals("1"))
     sreturn = sreturn + "日";
   }
  } else {
   // 不是空值,也是一个合法的日期值,则先将其转换为标准的时间格式
   sdate = roc.util.RocDate.getOKDate(sdate);
   s_nd = sdate.substring(0, 4); // 年份
   s_yf = sdate.substring(5, 7); // 月份
   s_rq = sdate.substring(8, 10); // 日期
   if (nd.equals("1")) {
    sreturn = s_nd;
    // 处理间隔符
    if (format.equals("1"))
     sreturn = sreturn + "年";
    else if (format.equals("2"))
     sreturn = sreturn + "-";
    else if (format.equals("3"))
     sreturn = sreturn + "/";
    else if (format.equals("5"))
     sreturn = sreturn + ".";
   }
   // 处理月份
   if (yf.equals("1")) {
    sreturn = sreturn + s_yf;
    if (format.equals("1"))
     sreturn = sreturn + "月";
    else if (format.equals("2"))
     sreturn = sreturn + "-";
    else if (format.equals("3"))
     sreturn = sreturn + "/";
    else if (format.equals("5"))
     sreturn = sreturn + ".";
   }
   // 处理日期
   if (rq.equals("1")) {
    sreturn = sreturn + s_rq;
    if (format.equals("1"))
     sreturn = sreturn + "日";
   }
  }
  return sreturn;
 }

 public static String getNextMonthDay(String sdate, int m) {
  sdate = getOKDate(sdate);
  int year = Integer.parseInt(sdate.substring(0, 4));
  int month = Integer.parseInt(sdate.substring(5, 7));
  month = month + m;
  if (month < 0) {
   month = month + 12;
   year = year - 1;
  } else if (month > 12) {
   month = month - 12;
   year = year + 1;
  }
  String smonth = "";
  if (month < 10)
   smonth = "0" + month;
  else
   smonth = "" + month;
  return year + "-" + smonth + "-10";
 }

 public static String getOKDate(String sdate) {
  if (sdate == null || sdate.equals(""))
   return getStringDateShort();

  if (!VeStr.Isdate(sdate)) {
   sdate = getStringDateShort();
  }
  // 将“/”转换为“-”
  sdate = VeStr.Replace(sdate, "/", "-");
  // 如果只有8位长度,则要进行转换
  if (sdate.length() == 8)
   sdate = sdate.substring(0, 4) + "-" + sdate.substring(4, 6) + "-" + sdate.substring(6, 8);
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  ParsePosition pos = new ParsePosition(0);
  Date strtodate = formatter.parse(sdate, pos);
  String dateString = formatter.format(strtodate);
  return dateString;
 }

 public static void main(String[] args) throws Exception {
  try {
   //System.out.print(Integer.valueOf(getTwoDay("2006-11-03 12:22:10", "2006-11-02 11:22:09")));
  } catch (Exception e) {
   throw new Exception();
  }
  //System.out.println("sss");
 }

分享到:
评论

相关推荐

    文化遗产保护:MATLAB点云处理在古建筑形变监测中的实践.pdf

    文档支持目录章节跳转同时还支持阅读器左侧大纲显示和章节快速定位,文档内容完整、条理清晰。文档内所有文字、图表、函数、目录等元素均显示正常,无任何异常情况,敬请您放心查阅与使用。文档仅供学习参考,请勿用作商业用途。 你是否渴望高效解决复杂的数学计算、数据分析难题?MATLAB 就是你的得力助手!作为一款强大的技术计算软件,MATLAB 集数值分析、矩阵运算、信号处理等多功能于一身,广泛应用于工程、科学研究等众多领域。 其简洁直观的编程环境,让代码编写如同行云流水。丰富的函数库和工具箱,为你节省大量时间和精力。无论是新手入门,还是资深专家,都能借助 MATLAB 挖掘数据背后的价值,创新科技成果。别再犹豫,拥抱 MATLAB,开启你的科技探索之旅!

    敏感图片敏感图片敏感图片敏感图片敏感图片敏感图片11

    敏感图片敏感图片敏感图片敏感图片敏感图片敏感图片11敏感图片敏感图片敏感图片敏感图片敏感图片敏感图片1122

    通信管道统建工程施工合同.docx

    通信管道统建工程施工合同.docx

    挂载网盘到本地工具.zip

    挂载网盘到本地工具.zip

    Spatial intelligence and geography 空间智能和地理.doc

    Spatial intelligence and geography 空间智能和地理.doc

    黑板风格毕业答辩模板25个

    黑板风格毕业答辩模板是一系列富有创意和趣味性的答辩文档模板,专为追求独特表达的大学生设计。这25个模板模拟了传统黑板的效果,结合了手绘风格与现代设计理念,使得内容呈现既生动又具学术感。每个模板都强调清晰的结构和易于理解的布局,适用于各类学科和研究领域,帮助学生有效地展示研究成果和核心观点。 黑板风格不仅带来亲切感,还能唤起人们对课堂学习的回忆,为答辩增添了轻松而专业的氛围。这些模板配备了丰富的图标、示意图和配色,既美观又实用,能够帮助学生在答辩中更好地吸引评审的注意力,增强信息的传达效果。无论是科技、艺术还是人文社科,黑板风格毕业答辩模板都能够为你的演示增添一份独特的魅力,提升你的表现,助力你在毕业答辩中取得成功。

    世邦魏理仕:2021年重庆房地产市场回顾与2022年展望.pdf

    世邦魏理仕:2021年重庆房地产市场回顾与2022年展望

    IMG_20250416_154916.jpg

    IMG_20250416_154916.jpg

    智慧农业大数据平台解决方案PPT(65页).pptx

    智慧农业,作为现代农业的新篇章,正引领着农业生产的革命性变革。本解决方案以物联网、云计算、大数据等先进技术为核心,为农业生产打造了一套全面、智能的管理系统。 想象一下,从温室大棚到广袤田野,智能传感器遍布每个角落,它们能实时感知空气温湿度、土壤水分、光照强度等环境参数,仿佛为农作物装上了“眼睛”和“耳朵”。这些数据通过物联网技术传输到云端,经过大数据分析,为农民提供精准的种植建议,如何时灌溉、施肥、防虫,让农业生产变得更加科学、高效。 更有趣的是,通过智慧农业平台,农民可以远程监控作物生长情况,甚至用手机就能控制温室大棚的遮阳板、通风设备等,实现“指尖上的农业”。此外,方案还包含了农产品可追溯系统,从田间到餐桌,每一步都可追溯,让消费者吃得放心。而智慧农业电商平台,则让农产品销售更加便捷,农民直接对接市场,收益倍增。 总之,这套智慧农业解决方案不仅让农业生产变得更加智能、高效,还提升了农产品的质量和安全,为农民带来了实实在在的收益,开启了农业现代化的新篇章。 对于想要投身智慧农业领域的你来说,这不仅仅是一套解决方案,更是一把开启现代农业大门的钥匙,引领你走向更加辉煌的未来。

    自动承保新员工示例-雇主责任险

    自动承保新员工示例-雇主责任险

    Java编程实现Redis集群连接与操作:含密码配置及异常处理机制设计了文档的主要内容

    内容概要:本文档主要介绍了Java代码连接Redis集群的方法,包括早期尝试的代码和修正后的有效代码。早期代码使用了`ShardedJedisPool`来管理多个`JedisShardInfo`对象,并设置了连接池参数和密码认证。然而,这段代码在实际的Redis集群环境中无法正常运行。修正后的代码采用了`JedisCluster`类,并通过配置连接池参数、设置密码以及定义集群节点信息,实现了与Redis集群的成功连接。此外,还提供了获取哈希表数据和集合数据的示例方法。 适合人群:具备一定Java编程经验,尤其是对Redis有一定了解的研发人员。 使用场景及目标:①学习如何正确配置Java代码连接Redis集群,包括设置连接池参数、密码认证和集群节点信息;②掌握通过`JedisCluster`类进行基本的Redis操作,如获取哈希表数据和集合数据。 阅读建议:读者应重点关注修正后的代码部分,理解其相对于早期代码的改进之处,特别是关于`JedisCluster`类的使用方法及其在连接Redis集群中的优势。同时,在实践中可以根据自己的需求调整连接池参数和密码配置。

    通信基站几种供电方案比较.doc

    通信基站几种供电方案比较.doc

    MCP协议从原理到开发保姆级教程.pdf

    内容概要:本文详细介绍了MCP(Model Context Protocol,模型上下文协议)的原理与开发流程。MCP协议起源于2024年11月25日Anthropic发布的文章,旨在解决不同AI模型间工具调用的碎片化问题,提供标准化接入方式,实现多功能应用与创新体验。文章首先解释了MCP的核心概念及其重要性,接着深入探讨了MCP Server和Client的开发步骤,包括项目搭建、工具注册、资源创建、提示符配置以及调试方法。此外,还讲解了MCP的工作原理,特别是C/S架构、JSON-RPC 2.0协议的应用,以及模型如何选择和执行工具。最后,通过一个实际案例展示了如何利用MCP协议构建一个企业微信机器人,实现查询知识库并将结果发送到群聊中。 适合人群:具备一定编程基础,对AI模型集成、标准化开发感兴趣的开发者,尤其是从事大语言模型相关工作的工程师。 使用场景及目标:①解决多模型集成中的工具调用标准化问题;②构建具备多种功能的企业级AI应用,如邮件发送、图像生成等;③学习如何通过MCP协议实现模型决策与工具执行的解耦,提升开发效率和用户体验。 阅读建议:本文适合有一定编程经验的读者,尤其是对AI模型集成有需求的技术人员。建议读者跟随文中提供的示例代码进行实践,理解MCP协议的核心机制,并尝试构建自己的MCP应用。同时,关注官方文档和社区动态,以获取最新的技术支持和开发指南。

    bofangBEEP.zip

    bofangBEEP

    【微电网优化】基于matlab改进的粒子群算法求解含风光柴储的微电网模型问题【含Matlab源码 13169期】.zip

    Matlab领域上传的视频是由对应的完整代码运行得来的,完整代码皆可运行,亲测可用,适合小白; 1、从视频里可见完整代码的内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作

    Qt+Opencv 显示多摄像头画面

    Qt+Opencv 显示多摄像头画面

    金融领域中国房地产行业2023年信用展望:政策支持与债务压力下的市场前景分析

    文章基于彭博专业服务提供的数据,对中国房地产行业2023年的信用展望进行了详细分析。首先,中国政府出台了16项措施支持房地产行业发展,旨在打破行业恶性循环并改善地产商的现金流状况。政府的支持措施包括银行贷款、信托展期、债券发行计划等,这些措施有助于缓解地产商的资金压力,但效果取决于贷款规模。其次,文章指出,若政府持续提供支持,房地产销售有望复苏,尤其是投资级地产商的现金覆盖率较高,能更好地应对债务到期压力。然而,高收益地产商的现金覆盖率较低,面临更大的再融资风险。此外,2023年中资地产债到期规模较大,尤其是在第一季度和第二季度,可能导致再融资缺口扩大。最后,文章分析了不同评级地产商的债券表现,指出投资级地产债可能面临与高收益地产债类似的再融资压力,而高收益地产债的价格已接近历史低点,进一步下行空间有限。

    第十一章:链表和共用体的个别例子

    第十一章:链表和共用体的个别例子,第十一章:链表和共用体的个别例子,第十一章:链表和共用体的个别例子

    tranformer.py

    这个实现是基础的 Transformer 层,可以根据需要扩展,例如加入位置编码、掩码机制等。

    微机原理笔记-计算机中的进制与码制(一)

    西电周佳社老师的微机原理课笔记,本节内容主要是二进制十进制之间转换的几种方法

Global site tag (gtag.js) - Google Analytics