java日期操作大全

  1. public static final String FormatDayToChinaTime24H = "yyyy年MM月dd日";   
  2.   
  3.     /**  
  4.      * 将yyyy-mm-dd转为yyyy-m-d  
  5.      *   
  6.      * @param day  
  7.      *            距离现在之后的天数  
  8.      * @return Date:距离现在之后的若干天的日期;  
  9.      */  
  10.     public static String getYMDDays(String day){   
  11.         String dayTime=day;   
  12.         if(String.valueOf(day.charAt(8)).equals("0"))dayTime=day.substring(0,8)+day.substring(9);   
  13.         if(String.valueOf(day.charAt(5)).equals("0"))dayTime=dayTime.substring(0,5)+dayTime.substring(6);   
  14.         return dayTime;   
  15.     }   
  16.        
  17.        
  18.     /**  
  19.      * 两个日期间的天数  
  20.      *   
  21.      * @param days  
  22.      *            距离现在之后的天数  
  23.      * @return Date:距离现在之后的若干天的日期;  
  24.      */  
  25.     public static int getIntervalDays(Date startday,Date endday){           
  26.         if(startday.after(endday)){   
  27.             Date cal=startday;   
  28.             startday=endday;   
  29.             endday=cal;   
  30.         }           
  31.         long sl=startday.getTime();   
  32.         long el=endday.getTime();          
  33.         long ei=el-sl;              
  34.         return (int)(ei/(1000*60*60*24));   
  35.     }   
  36.   
  37.        
  38.        
  39.     /**  
  40.      * 取得距离现在多少天(距离现在之后的若干天)  
  41.      *   
  42.      * @param days  
  43.      *            距离现在之后的天数  
  44.      * @return Date:距离现在之后的若干天的日期;  
  45.      */  
  46.     public static Date getDate(int days) {   
  47.         Date dateresult = new Date();   
  48.         try {   
  49.             DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL);   
  50.             // Create our Gregorian Calendar.   
  51.             GregorianCalendar cal = new GregorianCalendar();   
  52.   
  53.             // Set the date and time of our calendar   
  54.             // to the system&s date and time   
  55.             cal.setTime(new Date());   
  56.             cal.add(GregorianCalendar.DAY_OF_MONTH, days);   
  57.             dateresult = cal.getTime();   
  58.         } catch (Exception e) {   
  59.             System.out.println("exception" + e.toString());   
  60.         }   
  61.         return dateresult;   
  62.     }   
  63.   
  64.     /**  
  65.      * @根据当前日期计算n天后的日期  
  66.      * @return String  
  67.      */  
  68.     public static Date afterNDay(Date date, int n) {   
  69.         Calendar c = Calendar.getInstance();   
  70.         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");   
  71.         c.setTime(date);   
  72.         c.add(Calendar.DATE, n);   
  73.         Date d2 = c.getTime();   
  74.         // String s=df.format(d2);   
  75.         return d2;   
  76.     }   
  77.        
  78.     /**  
  79.      * @根据当前日期计算n天后的日期  
  80.      * @return String  
  81.      */  
  82.     public static String afterDay(Date date, int n) {   
  83.         Calendar c = Calendar.getInstance();   
  84.         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");   
  85.         // String s=df.format(d2);   
  86.         return df.toString();   
  87.     }   
  88.   
  89.     /**  
  90.      * @获取当前时间是星期几,“星期日”  
  91.      * @return String  
  92.      */  
  93.     public static String getDayInWeek() {   
  94.         Date today = new Date(System.currentTimeMillis());   
  95.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E");   
  96.         return simpleDateFormat.format(today);   
  97.     }   
  98.     /**  
  99.      *   
  100.      * @跟具字符串时间来获得星期几,(SimpleDateFormat("yyyy-MM-dd"))  
  101.      * @return  
  102.      */  
  103. public static String getDayInWeek(String mydatestring) {   
  104.      SimpleDateFormat   dateFormat   =   new   SimpleDateFormat("yyyy-MM-dd");      
  105.      Date   date   =   null;    
  106.      String   showDate   ="";    
  107.      try   {      
  108.              date   =   dateFormat.parse(mydatestring);      
  109.      }   catch   (ParseException   e)   {      
  110.   
  111.      }      
  112.      Calendar   cd   =   Calendar.getInstance();      
  113.      cd.setTime(date);      
  114.      int   mydate   =   cd.get(Calendar.DAY_OF_WEEK);      
  115.        
  116.      switch   (mydate)   {      
  117.      case   1:      
  118.              showDate   =   "星期日";      
  119.              break;      
  120.      case   2:      
  121.              showDate   =   "星期一";      
  122.              break;      
  123.      case   3:      
  124.              showDate   =   "星期二";      
  125.              break;      
  126.      case   4:      
  127.              showDate   =   "星期三";      
  128.              break;      
  129.      case   5:      
  130.              showDate   =   "星期四";      
  131.              break;      
  132.      case   6:      
  133.              showDate   =   "星期五";      
  134.              break;      
  135.      default:      
  136.              showDate   =   "星期六";      
  137.              break;      
  138.      }      
  139.   
  140.     return showDate;   
  141.        
  142. }   
  143.     /**  
  144.      * @根据日期时间,获取当前时间是星期几,“星期日”  
  145.      * @return String  
  146.      */  
  147.     public static String getDayInWeek(Date date) {   
  148.         if (date == null)   
  149.             return "";   
  150.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E");   
  151.         return simpleDateFormat.format(date);   
  152.     }   
  153.   
  154.     /**  
  155.      * @获取当前时间在这个月的天  
  156.      * @return String  
  157.      */  
  158.     public static String getDayInMonth() {   
  159.         Date today = new Date(System.currentTimeMillis());   
  160.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d");   
  161.         return simpleDateFormat.format(today);   
  162.     }   
  163.   
  164.     /**  
  165.      * @根据日期,获取当前时间在这个月的天  
  166.      * @return String  
  167.      */  
  168.     public static String getDayInMonth(Date date) {   
  169.         if (date == null)   
  170.             return "";   
  171.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d");   
  172.         return simpleDateFormat.format(date);   
  173.     }   
  174.   
  175.     /**  
  176.      * @根据在本年当中,获取月份格式"M"  
  177.      * @return String  
  178.      */  
  179.     public static String getMonthInYear() {   
  180.         Date today = new Date(System.currentTimeMillis());   
  181.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M");   
  182.         return simpleDateFormat.format(today);   
  183.     }   
  184.   
  185.     /**  
  186.      * @根据在本年当中,获取月份格式"MM"  
  187.      * @return String  
  188.      */  
  189.     public static String getMonthInYear2() {   
  190.         java.util.Date today = new Date(System.currentTimeMillis());   
  191.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM");   
  192.         return simpleDateFormat.format(today);   
  193.     }   
  194.   
  195.     /**  
  196.      * @根据日期,获取月份格式"MM"  
  197.      * @return String  
  198.      */  
  199.     public static String getMonthInYear2(String formatDate) {   
  200.         java.util.Date day = getDate(formatDate, "yyyy-MM-dd");   
  201.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM");   
  202.         return simpleDateFormat.format(day);   
  203.     }   
  204.   
  205.     /**  
  206.      * @获取当前时间的年,格式"yyyy"  
  207.      * @return String  
  208.      */  
  209.     public static String getYear() {   
  210.         java.util.Date today = new java.util.Date(System.currentTimeMillis());   
  211.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");   
  212.         return simpleDateFormat.format(today);   
  213.     }   
  214.   
  215.     /**  
  216.      * @根据时间,获取年,格式"yyyy"  
  217.      * @return String  
  218.      */  
  219.     public static String getYear(String formatDate) {   
  220.         java.util.Date day = getDate(formatDate, "yyyy-MM-dd");   
  221.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");   
  222.         return simpleDateFormat.format(day);   
  223.     }   
  224.   
  225.     /**  
  226.      * @根据日期以及日期格式,获取日期字符串表达  
  227.      * @return String  
  228.      */  
  229.     public static String getFormatDate(java.util.Date thisDate, String format) {   
  230.         if (thisDate == null)   
  231.             return "";   
  232.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);   
  233.         return simpleDateFormat.format(thisDate);   
  234.     }   
  235.   
  236.     /**  
  237.      * @根据日期以及日期格式,获取日期  
  238.      * @return String  
  239.      */  
  240.     public static java.util.Date getDate(String date, String format) {   
  241.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);   
  242.         try {   
  243.             return simpleDateFormat.parse(date);   
  244.         } catch (ParseException ex) {   
  245.             return null;   
  246.         }   
  247.     }   
  248.   
  249.     /**  
  250.      * @返回系统当前月的第一天所表示的日期  
  251.      * @param monthDate  
  252.      *            Date  
  253.      * @return Date  
  254.      */  
  255.     public static java.util.Date getFirstDateMonth() {   
  256.         try {   
  257.             String date_s = getYear() + "-" + getMonthInYear2() + "-01";   
  258.             return getDate(date_s, "yyyy-MM-dd");   
  259.         } catch (Exception er) {   
  260.             er.printStackTrace();   
  261.         }   
  262.         return null;   
  263.     }   
  264.   
  265.     /**  
  266.      * @返回系统当前月的第一天所表示的日期  
  267.      * @param monthDate  
  268.      *            Date  
  269.      * @return Date  
  270.      */  
  271.     public static java.util.Date getFirstDateMonth(String formatDate) {   
  272.         try {   
  273.             String date_s = getYear(formatDate) + "-"  
  274.                     + getMonthInYear2(formatDate) + "-01";   
  275.             return getDate(date_s, "yyyy-MM-dd");   
  276.         } catch (Exception er) {   
  277.             er.printStackTrace();   
  278.         }   
  279.         return null;   
  280.     }   
  281.   
  282.     /**  
  283.      * @返回系统当前月的第一天所表示的日期  
  284.      * @param monthDate  
  285.      *            Date  
  286.      * @return Date  
  287.      */  
  288.     public static String getFirstDateMonthToString() {   
  289.         try {   
  290.             return getYear() + "-" + getMonthInYear2() + "-01";   
  291.         } catch (Exception er) {   
  292.             er.printStackTrace();   
  293.         }   
  294.         return null;   
  295.     }   
  296.   
  297.     /**  
  298.      * @返回系统当前月的第一天所表示的日期  
  299.      * @param monthDate  
  300.      *            Date  
  301.      * @return Date  
  302.      */  
  303.     public static String getFirstDateMonthToString(String formatDate) {   
  304.         try {   
  305.             return getYear(formatDate) + "-" + getMonthInYear2(formatDate)   
  306.                     + "-01";   
  307.         } catch (Exception er) {   
  308.             er.printStackTrace();   
  309.         }   
  310.         return null;   
  311.     }   
  312.   
  313.     /**  
  314.      * @返回系统当前月的最后一天所表示的日期  
  315.      * @return Date  
  316.      */  
  317.     public static java.util.Date getLastDateMonth() {   
  318.         try {   
  319.             int lastday = getDaySumInTheMonth();   
  320.             String date_s;   
  321.             if (lastday < 10)   
  322.                 date_s = getYear() + "-" + getMonthInYear2() + "-0" + lastday;   
  323.             else  
  324.                 date_s = getYear() + "-" + getMonthInYear2() + "-" + lastday;   
  325.             return getDate(date_s, "yyyy-MM-d");   
  326.         } catch (Exception er) {   
  327.             er.printStackTrace();   
  328.         }   
  329.         return null;   
  330.     }   
  331.   
  332.     /**  
  333.      * @返回系统当前月的最后一天所表示的日期  
  334.      * @return Date  
  335.      */  
  336.     public static String getLastDateMonthToString(String formatDate) {   
  337.         try {   
  338.             int lastday = getDaySumInTheMonth(formatDate);   
  339.             if (lastday < 10)   
  340.                 return getYear(formatDate) + "-" + getMonthInYear2(formatDate)   
  341.                         + "-0" + lastday;   
  342.             else  
  343.                 return getYear(formatDate) + "-" + getMonthInYear2(formatDate)   
  344.                         + "-" + lastday;   
  345.         } catch (Exception er) {   
  346.             er.printStackTrace();   
  347.         }   
  348.         return null;   
  349.     }   
  350.   
  351.     /**  
  352.      * @根据时间,返回最后一天所表示的日期  
  353.      * @param formatDate  
  354.      *            String  
  355.      * @return Date  
  356.      */  
  357.     public static java.util.Date getLastDateMonth(String formatDate) {   
  358.         try {   
  359.             int lastday = getDaySumInTheMonth(formatDate);   
  360.             String month = getMonthInYear2(formatDate);   
  361.             String year = getYear(formatDate);   
  362.             String date_s;   
  363.             if (lastday < 10)   
  364.                 date_s = year + "-" + month + "-0" + lastday;   
  365.             else  
  366.                 date_s = year + "-" + month + "-" + lastday;   
  367.   
  368.             System.out.println(date_s);   
  369.   
  370.             return getDate(date_s, "yyyy-MM-d");   
  371.         } catch (Exception er) {   
  372.             er.printStackTrace();   
  373.         }   
  374.         return null;   
  375.     }   
  376.   
  377.     /**  
  378.      * @获得这个月的天数  
  379.      * @return int  
  380.      */  
  381.     public static int getDaySumInTheMonth() {   
  382.         String month = DayFormat.getMonthInYear();   
  383.         if (month.equalsIgnoreCase("12"))   
  384.             return 31;   
  385.         int mon = Integer.parseInt(month);   
  386.         java.util.Date date = DayFormat.getDate(DayFormat.getYear() + "-"  
  387.                 + (mon + 1) + "-" + "1""yyyy-MM-d");   
  388.         Calendar cal = Calendar.getInstance();   
  389.         cal.setTime(date);   
  390.         cal.add(Calendar.DATE, -1);   
  391.         return Integer.parseInt(new SimpleDateFormat("dd")   
  392.                 .format(cal.getTime()));   
  393.     }   
  394.   
  395.     /**  
  396.      * @获得所在日期月份的天数  
  397.      * @return int  
  398.      */  
  399.     public static int getDaySumInTheMonth(java.util.Date date) {   
  400.         String month = new SimpleDateFormat("MM").format(date);   
  401.         if (month.equalsIgnoreCase("12"))   
  402.             return 31;   
  403.         int mon = Integer.parseInt(month);   
  404.         java.util.Date date2 = DayFormat.getDate(new SimpleDateFormat("yyyy")   
  405.                 .format(date)   
  406.                 + "-" + (mon + 1) + "-" + "1""yyyy-MM-d");   
  407.         Calendar cal = Calendar.getInstance();   
  408.         cal.setTime(date2);   
  409.         cal.add(Calendar.DATE, -1);   
  410.         return Integer.parseInt(new SimpleDateFormat("dd")   
  411.                 .format(cal.getTime()));   
  412.     }   
  413.   
  414.     /**  
  415.      * @获得所在日期月份的天数  
  416.      * @return int  
  417.      */  
  418.     public static int getDaySumInTheMonth(String formatDate) {   
  419.         String month = DayFormat.getMonthInYear2(formatDate);   
  420.         if (month.equalsIgnoreCase("12"))   
  421.             return 31;   
  422.         int mon = Integer.parseInt(month);   
  423.         java.util.Date date = DayFormat.getDate(DayFormat.getYear(formatDate)   
  424.                 + "-" + (mon + 1) + "-" + "1""yyyy-MM-d");   
  425.         Calendar cal = Calendar.getInstance();   
  426.         cal.setTime(date);   
  427.         cal.add(Calendar.DATE, -1);   
  428.         return Integer.parseInt(new SimpleDateFormat("dd")   
  429.                 .format(cal.getTime()));   
  430.     }   
  431.   
  432.     /**  
  433.      * @把日期格式转换成字符串格式,格式为'yyyy-MM-dd'  
  434.      * @param date  
  435.      *            Date  
  436.      * @return String  
  437.      */  
  438.     public static String getFormatDate(java.util.Date date) {   
  439.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");   
  440.         return simpleDateFormat.format(date);   
  441.     }   
  442.   
  443.     public final static String FormatDay1 = "yyyy-MM-dd";   
  444.     public final static String FormatDay2 = "yyyy年MM月dd日";   
  445.     public final static String FormatDay3 = "yyyy年MM月dd日 HH:mm:ss";   
  446.     public final static String FormatDay4 = "yyyy-MM-dd HH:mm";   
  447.   
  448.     public static final String Format24Datetime1 = "yyyy-MM-dd HH:mm:ss";// 24   
  449.   
  450.     public static final String Format12Datetime1 = "yyyy-MM-dd hh:mm:ss";// 12   
  451.   
  452.     /**  
  453.      * 获取当前时间  
  454.      *   
  455.      * @return  
  456.      */  
  457.     public static String getToday() {   
  458.         return getToday(FormatDay1);   
  459.     }   
  460.   
  461.     public static java.sql.Timestamp getCurrentTimestamp() {   
  462.         return new Timestamp(System.currentTimeMillis());   
  463.     }   
  464.   
  465.     public static java.util.Date getCurrentUtilDate() {   
  466.         return new java.util.Date(System.currentTimeMillis());   
  467.     }   
  468.   
  469.     public static String getToday(String formatDay) {   
  470.         java.util.Date today = new java.util.Date();   
  471.         SimpleDateFormat df = new SimpleDateFormat(formatDay);   
  472.         return df.format(today).toString();   
  473.     }   
  474.   
  475.     public static String get24DateTime() {   
  476.         return get24DateTime(Format24Datetime1);   
  477.     }   
  478.   
  479.     public static String get24DateTime(String format24DateTime) {   
  480.         java.util.Date today = new java.util.Date();   
  481.         SimpleDateFormat df = new SimpleDateFormat(format24DateTime);   
  482.         return df.format(today).toString();   
  483.     }   
  484.   
  485.     public static String get12DateTime() {   
  486.         return get12DateTime(Format12Datetime1);   
  487.     }   
  488.   
  489.     public static String get12DateTime(String format12DateTime) {   
  490.         java.util.Date today = new java.util.Date();   
  491.         SimpleDateFormat df = new SimpleDateFormat(format12DateTime);   
  492.         return df.format(today).toString();   
  493.     }   
  494.   
  495.     public static String get24DateTime(Timestamp timestamp) {   
  496.         SimpleDateFormat df = new SimpleDateFormat(Format24Datetime1);   
  497.         return df.format(timestamp).toString();   
  498.     }   
  499.   
  500.     public static String get12DateTime(Timestamp timestamp) {   
  501.         SimpleDateFormat df = new SimpleDateFormat(Format12Datetime1);   
  502.         return df.format(timestamp).toString();   
  503.     }   
  504.   
  505.     // STRING到日期   
  506.     public static java.sql.Date stringToDate(String dateStr) {   
  507.         return java.sql.Date.valueOf(dateStr);   
  508.     }   
  509.   
  510.     public static java.sql.Timestamp stringToTimestamp(String timestampStr) {   
  511.         if (timestampStr == null || timestampStr.length() < 1)   
  512.             return null;   
  513.         return java.sql.Timestamp.valueOf(timestampStr);   
  514.     }   
  515.   
  516.     public static java.sql.Timestamp stringToTimestamp2(String dateStr) {   
  517.         if (dateStr == null || dateStr.length() < 1)   
  518.             return null;   
  519.         return java.sql.Timestamp.valueOf(dateStr + " 00:00:00.000000000");   
  520.     }   
  521.   
  522.     public static java.sql.Timestamp stringToTimestamp3(String dateStr) {   
  523.         if (dateStr == null || dateStr.length() < 1)   
  524.             return null;   
  525.         return java.sql.Timestamp.valueOf(dateStr + ":00.000000000");   
  526.     }   
  527.   
  528.     public static java.sql.Time stringToTime(String timeStr) {   
  529.         return java.sql.Time.valueOf(timeStr);   
  530.     }   
  531.   
  532.     // 日期到STRING   
  533.     public static String dateToString(java.sql.Date datee) {   
  534.         return datee.toString();   
  535.     }   
  536.   
  537.     public static String timestampToString(java.sql.Timestamp timestampe) {   
  538.         return timestampe.toString();   
  539.     }   
  540.   
  541.     public static String timestampToStringForFormat(Timestamp timestamp,   
  542.             String format) {   
  543.         if (timestamp == null)   
  544.             return "";   
  545.         SimpleDateFormat df = new SimpleDateFormat(format);   
  546.         return df.format(timestamp).toString();   
  547.     }   
  548.   
  549.     public static String getTimestampToDateTime15Len(   
  550.             java.sql.Timestamp timestampe) {   
  551.         if (timestampe == null || timestampe.toString().length() < 1)   
  552.             return "";   
  553.         return timestampe.toString().substring(016);   
  554.     }   
  555.   
  556.     public static String timeToString(java.sql.Time timee) {   
  557.         return timee.toString();   
  558.     }   
  559.   
  560.     public static java.sql.Timestamp StringToTimestamp(String dateString)   
  561.             throws ParseException {   
  562.         java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(   
  563.                 FormatDay1);   
  564.         formatter.setLenient(false);   
  565.         return new java.sql.Timestamp((formatter.parse(dateString).getTime()));   
  566.     }   
  567.   
  568.     public static java.sql.Timestamp StringToTimestampAll(String dateString)   
  569.             throws ParseException {   
  570.         return java.sql.Timestamp.valueOf(dateString);   
  571.     }   
  572.     //获得周日的日期    
  573.     public   static   String   getSunday(Date   date){      
  574.         Calendar   c   =   Calendar.getInstance();      
  575.         c.setTime(date);      
  576.         c.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);      
  577.         return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());      
  578.       }       
  579.       //获得周一的日期      
  580.       public   static   String   getMonday(Date   date){      
  581.         Calendar   c   =   Calendar.getInstance();      
  582.         c.setTime(date);      
  583.         c.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);      
  584.         return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());      
  585.       }      
  586.       //获得周二的日期   
  587.       public   static   String   getTuesday(Date   date){      
  588.           Calendar   c   =   Calendar.getInstance();      
  589.           c.setTime(date);      
  590.           c.set(Calendar.DAY_OF_WEEK,Calendar.TUESDAY);      
  591.           return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());      
  592.         }    
  593.       //获得周三的日期    
  594.       public   static   String   getWednesday(Date   date){      
  595.           Calendar   c   =   Calendar.getInstance();      
  596.           c.setTime(date);      
  597.           c.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);      
  598.           return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());      
  599.         }    
  600.       //获得周四的日期   
  601.       public   static   String   getThursday(Date   date){      
  602.           Calendar   c   =   Calendar.getInstance();      
  603.           c.setTime(date);      
  604.           c.set(Calendar.DAY_OF_WEEK,Calendar.THURSDAY);      
  605.           return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());      
  606.         }    
  607.       //获得周五的日期      
  608.       public   static   String   getFriday(Date   date){      
  609.         Calendar   c   =   Calendar.getInstance();      
  610.         c.setTime(date);      
  611.         c.set(Calendar.DAY_OF_WEEK,Calendar.FRIDAY);            
  612.         return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());          
  613.       }      
  614.       //获得周六的日期    
  615.       public   static   String   getSaturday(Date   date){      
  616.           Calendar   c   =   Calendar.getInstance();      
  617.           c.setTime(date);      
  618.           c.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);      
  619.           return   new   SimpleDateFormat("yyyy-MM-dd").format(c.getTime());      
  620.         }    
  621.     
  622.     public static void main(String args[]) {   
  623.         try {   
  624.             String d = "2007-05-15 19:23:48.703";   
  625.             System.out.println(d);   
  626.             java.sql.Timestamp timestampe = java.sql.Timestamp.valueOf(d);   
  627.             System.out.println(timestampe.toString());   
  628.         } catch (Exception er) {   
  629.             er.printStackTrace();   
  630.         }   
  631.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值