org.apache.kylin.common.util.DateFormat.isAllDigits()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.apache.kylin.common.util.DateFormat.isAllDigits()方法的一些代码示例,展示了DateFormat.isAllDigits()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateFormat.isAllDigits()方法的具体详情如下:
包路径:org.apache.kylin.common.util.DateFormat
类名称:DateFormat
方法名:isAllDigits

DateFormat.isAllDigits介绍

暂无

代码示例

代码示例来源:origin: apache/kylin

public static long stringToMillis(String str) {
  // try to be smart and guess the date format
  if (isAllDigits(str)) {
    if (str.length() == 8 && isInputFormatDate(str, COMPACT_DATE_PATTERN))
      //TODO: might be prolematic if an actual ts happends to be 8 digits, e.g. 1970-01-01 10:00:01.123
      return stringToDate(str, COMPACT_DATE_PATTERN).getTime();
    else if (str.length() == 10 && isInputFormatDate(str, YYYYMMDDHH))
      return stringToDate(str, YYYYMMDDHH).getTime();
    else if (str.length() == 12 && isInputFormatDate(str, YYYYMMDDHHMM))
      return stringToDate(str, YYYYMMDDHHMM).getTime();
    else if (str.length() == 14 && isInputFormatDate(str, YYYYMMDDHHMMSS))
      return stringToDate(str, YYYYMMDDHHMMSS).getTime();
    else
      return Long.parseLong(str);
  } else if (str.length() == 10) {
    return stringToDate(str, DEFAULT_DATE_PATTERN).getTime();
  } else if (str.length() == 13) {
    return stringToDate(str, YYYY_MM_DD_HH).getTime();
  } else if (str.length() == 16) {
    return stringToDate(str, YYYY_MM_DD_HH_MM).getTime();
  } else if (str.length() == 19) {
    return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS).getTime();
  } else if (str.length() > 19) {
    return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITH_MILLISECONDS).getTime();
  } else {
    throw new IllegalArgumentException("there is no valid date pattern for:" + str);
  }
}

代码示例来源:origin: org.apache.kylin/kylin-common

public static long stringToMillis(String str) {
  if (isAllDigits(str)) {
    return Long.parseLong(str);
  } else if (str.length() == 10) {
    return stringToDate(str, DEFAULT_DATE_PATTERN).getTime();
  } else if (str.length() == 19) {
    return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS).getTime();
  } else if (str.length() == 23) {
    return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITH_MILLISECONDS).getTime();
  } else {
    throw new IllegalArgumentException("there is no valid date pattern for:" + str);
  }
}

代码示例来源:origin: org.apache.kylin/kylin-core-common

public static long stringToMillis(String str) {
  // try to be smart and guess the date format
  if (isAllDigits(str)) {
    if (str.length() == 8 && isInputFormatDate(str, COMPACT_DATE_PATTERN))
      //TODO: might be prolematic if an actual ts happends to be 8 digits, e.g. 1970-01-01 10:00:01.123
      return stringToDate(str, COMPACT_DATE_PATTERN).getTime();
    else if (str.length() == 10 && isInputFormatDate(str, YYYYMMDDHH))
      return stringToDate(str, YYYYMMDDHH).getTime();
    else if (str.length() == 12 && isInputFormatDate(str, YYYYMMDDHHMM))
      return stringToDate(str, YYYYMMDDHHMM).getTime();
    else if (str.length() == 14 && isInputFormatDate(str, YYYYMMDDHHMMSS))
      return stringToDate(str, YYYYMMDDHHMMSS).getTime();
    else
      return Long.parseLong(str);
  } else if (str.length() == 10) {
    return stringToDate(str, DEFAULT_DATE_PATTERN).getTime();
  } else if (str.length() == 13) {
    return stringToDate(str, YYYY_MM_DD_HH).getTime();
  } else if (str.length() == 16) {
    return stringToDate(str, YYYY_MM_DD_HH_MM).getTime();
  } else if (str.length() == 19) {
    return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS).getTime();
  } else if (str.length() > 19) {
    return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITH_MILLISECONDS).getTime();
  } else {
    throw new IllegalArgumentException("there is no valid date pattern for:" + str);
  }
}

相关文章