congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
DateUtil
Code IndexAdd Tabnine to your IDE (free)

How to use
DateUtil
in
cn.jiangzeyin

Best Java code snippets using cn.jiangzeyin.DateUtil (Showing top 10 results out of 315)

origin: cn.jiangzeyin/simple-util

/**
 * 获取当前指定格式时间
 *
 * @param pattern 格式
 * @return 结果
 */
public static String getCurrentFormatTime(String pattern) {
  return formatTime(pattern, getCurrentTimeMillis());
}
origin: cn.jiangzeyin/simple-util

/**
 * 字符串时间转date
 *
 * @param time    字符串时间
 * @param pattern 时间格式
 * @return date
 * @throws ParseException 装换异常
 */
public static Date parseTime(String time, String pattern) throws ParseException {
  SimpleDateFormat sdf = getDateFormat(pattern);
  return sdf.parse(time);
}
origin: cn.jiangzeyin/simple-util

public static Date formatTimeStamp(int date) {
  return formatTime(date * 1000L);
}
origin: cn.jiangzeyin/simple-util

/**
 * @return 当前10位时间戳
 */
public static int getCurrentShortTimeMillis() {
  return (int) (getCurrentTimeMillis() / 1000L);
}
origin: cn.jiangzeyin/simple-util

/**
 * 获取当前日期相关int
 *
 * @param pattern 需要的格式
 * @return int
 */
public static int getCurrentFormatTimeInt(String pattern) {
  return StringUtil.parseInt(getCurrentFormatTime(pattern), -1);
}
origin: cn.jiangzeyin/dbutil

  @Override
  public JSONObject parseInfo(String id) {
    id = Long.toBinaryString(Long.parseLong(id));
    int len = id.length();
    JSONObject jsonObject = new JSONObject();
    int sequenceStart = len < workerIdShift ? 0 : len - workerIdShift;
    int workerStart = len < dataCenterIdShift ? 0 : len - dataCenterIdShift;
    int timeStart = len < timestampLeftShift ? 0 : len - timestampLeftShift;
    String sequence = id.substring(sequenceStart, len);
    String workerId = sequenceStart == 0 ? "0" : id.substring(workerStart, sequenceStart);
    String dataCenterId = workerStart == 0 ? "0" : id.substring(timeStart, workerStart);
    String time = timeStart == 0 ? "0" : id.substring(0, timeStart);
    int sequenceInt = Integer.valueOf(sequence, 2);
    jsonObject.put("sequence", sequenceInt);
    int workerIdInt = Integer.valueOf(workerId, 2);
    jsonObject.put("workerId", workerIdInt);
    int dataCenterIdInt = Integer.valueOf(dataCenterId, 2);
    jsonObject.put("dataCenter", dataCenterIdInt);
    long diffTime = Long.parseLong(time, 2);
    long timeLong = diffTime + startTime;
    String date = DateUtil.formatTime(null, timeLong);
    jsonObject.put("date", date);
    return jsonObject;
  }
}
origin: cn.jiangzeyin/dbutil

@Override
public synchronized String nextId() {
  //获取当前毫秒数
  long timestamp = timeGen();
  //如果服务器时间有问题(时钟后退) 报错。
  if (timestamp < lastTimestamp) {
    throw new RuntimeException(String.format(
        "Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
  }
  //如果上次生成时间和当前时间相同,在同一毫秒内
  if (lastTimestamp == timestamp) {
    //sequence自增,因为sequence只有12bit,所以和sequenceMask相与一下,去掉高位
    sequence = (sequence + 1) & sequenceMask;
    //判断是否溢出,也就是每毫秒内超过4095,当为4096时,与sequenceMask相与,sequence就等于0
    if (sequence == 0) {
      //自旋等待到下一毫秒
      timestamp = tilNextMillis(lastTimestamp);
    }
  } else {
    //如果和上次生成时间不同,重置sequence,就是下一毫秒开始,sequence计数重新从0开始累加
    sequence = 0L;
  }
  lastTimestamp = timestamp;
  long suffix = (dataCenterId << dataCenterIdShift) | (workerId << workerIdShift) | sequence;
  String datePrefix = DateUtil.formatTime("yyyyMMddHHmmssSSS", timestamp);
  return datePrefix + suffix;
}
origin: cn.jiangzeyin/simple-util

  /**
   * 根据日期 找到对应日期的 星期
   */
  public static String getDayOfWeekByDate(String date) throws ParseException {
    SimpleDateFormat myFormatter = getDateFormat("yyyy-MM-dd");// new SimpleDateFormat("yyyy-MM-dd");
    Date myDate = myFormatter.parse(date);
    SimpleDateFormat formatter = getDateFormat("E");// new SimpleDateFormat("E");
    return formatter.format(myDate);
  }
}
origin: cn.jiangzeyin/simple-util

/**
 * 格式化13位时间戳
 *
 * @param pattern    格式
 * @param timeMillis 13位时间戳
 * @return 结果
 * @author jiangzeyin
 */
public static String formatTime(String pattern, long timeMillis) {
  if (pattern == null || pattern.length() == 0)
    pattern = "yyyy-MM-dd HH:mm:ss";
  SimpleDateFormat sdf = getDateFormat(pattern);
  return sdf.format(timeMillis);
}
origin: cn.jiangzeyin/simple-util

/**
 * 格式化10位时间戳
 *
 * @param pattern    格式
 * @param timeMillis 10位时间戳
 * @return 结果
 * @author jiangzeyin
 */
public static String formatTimeStamp(String pattern, int timeMillis) {
  if (pattern == null || pattern.length() == 0)
    pattern = "yyyy-MM-dd HH:mm:ss";
  Calendar nowDate = new GregorianCalendar();
  nowDate.setTimeInMillis(timeMillis * 1000L);
  SimpleDateFormat df = getDateFormat(pattern);
  return df.format(nowDate.getTime());
}
cn.jiangzeyinDateUtil

Javadoc

时间工具类 Created by jiangzeyin on 2017/11/29.

Most used methods

  • formatTime
    格式化13位时间戳
  • getCurrentFormatTime
    获取当前指定格式时间
  • getCurrentTimeMillis
  • getDateFormat
    获取线程安全的日期格式化对象

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • JButton (javax.swing)
  • JTable (javax.swing)
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • 21 Best Atom Packages for 2021
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now