字符串类型转Timestamp类型

为什么80%的码农都做不了架构师?>>>   hot3.png

Timestamp.valueOf(DateUtil.curDate())

/**DateUtil**/

package com.snack.util;


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

public class DateUtil {
 private static SimpleDateFormat format = null;
 public static String curDate()
 {
  format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  return format.format(new Date());
 }
 public static String curDateAndRandom()
 {
  format = new SimpleDateFormat("yyyyMMddHHmmss");
  Random ra = new Random();
  return format.format(new Date())+ra.nextInt(9999);
 }
 public static String chinaMonth(String month){
  switch (Integer.valueOf(month)) {
  case 1:
   return "一";
  case 2:
   return "二";
  case 3:
   return "三";
  case 4:
   return "四";
  case 5:
   return "五";
  case 6:
   return "六";
  case 7:
   return "七";
  case 8:
   return "八";
  case 9:
   return "九";
  case 10:
   return "十";
  case 11:
   return "十一";
  default:
   return "十二";
  }
 }

 public static int monthDay(String str){
  int year = Integer.valueOf(str.substring(0,4));
  int month = Integer.valueOf(str.substring(5));
  switch (month) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
   return 31;
  case 2:
   if((year%4 == 0)&&((year%100 != 0)|(year%400 == 0))) {
    return 29;
   }else{
    return 28;
   }
  default:
   return 30;
  }
 }
}

 

转载于:https://my.oschina.net/HIJAY/blog/114121

你可能感兴趣的:(数据库,java,json)