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

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

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

DateFormat.stringToDate介绍

暂无

代码示例

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

public static Date stringToDate(String str) {
  return stringToDate(str, DEFAULT_DATE_PATTERN);
}

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

@Override
public boolean addValue(String value) {
  if (StringUtils.isBlank(value)) // empty string is treated as null
    return false;
  // detect date pattern on the first value
  if (datePattern == null) {
    for (String p : DATE_PATTERNS) {
      try {
        DateFormat.stringToDate(value, p);
        datePattern = p;
        break;
      } catch (Exception e) {
        // continue;
      }
    }
    if (datePattern == null)
      throw new IllegalArgumentException("Unknown date pattern for input value: " + value);
  }
  // check the date format
  DateFormat.stringToDate(value, datePattern);
  return true;
}

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

public static boolean isInputFormatDate(String dateStr, String formatStr) {
  try {
    return dateStr.equals(dateToString(stringToDate(dateStr, formatStr), formatStr));
  } catch (Exception ex) {
    return false;
  }
}

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

public static boolean isSupportedDateFormat(String dateStr) {
  assert dateStr != null;
  for (String formatStr : SUPPORTED_DATETIME_PATTERN) {
    try {
      if (dateStr.equals(dateToString(stringToDate(dateStr, formatStr), formatStr))) {
        return true;
      }
    } catch (Exception ex) {
      continue;
    }
  }
  return false;
}

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

@Override
final protected int getIdFromValueImpl(String value, int roundFlag) {
  Date date = stringToDate(value, pattern);
  int id = calcIdFromSeqNo((int) DateDimEnc.getNumOfDaysSince0000FromMillis(date.getTime()));
  if (id < baseId || id > maxId)
    throw new IllegalArgumentException("'" + value + "' encodes to '" + id + "' which is out of range [" + baseId + "," + maxId + "]");
  return id;
}

代码示例来源: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-core-common

public static Date stringToDate(String str) {
  return stringToDate(str, DEFAULT_DATE_PATTERN);
}

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

public static Date stringToDate(String str) {
  return stringToDate(str, DEFAULT_DATE_PATTERN);
}

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

@Override
public boolean addValue(String value) {
  if (StringUtils.isBlank(value)) // empty string is treated as null
    return false;
  // detect date pattern on the first value
  if (datePattern == null) {
    for (String p : DATE_PATTERNS) {
      try {
        DateFormat.stringToDate(value, p);
        datePattern = p;
        break;
      } catch (Exception e) {
        // continue;
      }
    }
    if (datePattern == null)
      throw new IllegalArgumentException("Unknown date pattern for input value: " + value);
  }
  // check the date format
  DateFormat.stringToDate(value, datePattern);
  return true;
}

代码示例来源: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 boolean isInputFormatDate(String dateStr, String formatStr) {
  try {
    return dateStr.equals(dateToString(stringToDate(dateStr, formatStr), formatStr));
  } catch (Exception ex) {
    return false;
  }
}

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

public static boolean isSupportedDateFormat(String dateStr) {
  assert dateStr != null;
  for (String formatStr : SUPPORTED_DATETIME_PATTERN) {
    try {
      if (dateStr.equals(dateToString(stringToDate(dateStr, formatStr), formatStr))) {
        return true;
      }
    } catch (Exception ex) {
      continue;
    }
  }
  return false;
}

代码示例来源: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);
  }
}

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

@Override
final protected int getIdFromValueImpl(String value, int roundFlag) {
  Date date = stringToDate(value, pattern);
  int id = calcIdFromSeqNo((int) DateDimEnc.getNumOfDaysSince0000FromMillis(date.getTime()));
  if (id < baseId || id > maxId)
    throw new IllegalArgumentException("'" + value + "' encodes to '" + id + "' which is out of range [" + baseId + "," + maxId + "]");
  return id;
}

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

@Override
final protected int getIdFromValueImpl(String value, int roundFlag) {
  Date date = DateFormat.stringToDate(value, pattern);
  int id = calcIdFromSeqNo(getNumOfDaysSince0000(date));
  if (id < baseId || id > maxId)
    throw new IllegalArgumentException("'" + value + "' encodes to '" + id + "' which is out of range [" + baseId + "," + maxId + "]");
  return id;
}

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

Date dateValue = DateFormat.stringToDate(strValue); // NOTE: forces GMT timezone
long millis = dateValue.getTime();
long days = millis / (1000 * 3600 * 24);

相关文章