本文整理了Java中org.apache.kylin.common.util.DateFormat
类的一些代码示例,展示了DateFormat
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateFormat
类的具体详情如下:
包路径:org.apache.kylin.common.util.DateFormat
类名称:DateFormat
暂无
代码示例来源:origin: apache/kylin
@Override
public long valueToCode(String value) {
long millis = DateFormat.stringToMillis(value);
return millis / 1000;
}
代码示例来源:origin: apache/kylin
public static String formatToDateStr(long millis) {
return formatToDateStr(millis, DEFAULT_DATE_PATTERN);
}
代码示例来源:origin: apache/kylin
case 1:
normalized = TimeUtil.getMinuteStart(t);
result.add(DateFormat.formatToTimeWithoutMilliStr(normalized));
break;
case 2:
normalized = TimeUtil.getHourStart(t);
result.add(DateFormat.formatToTimeWithoutMilliStr(normalized));
break;
case 3:
normalized = TimeUtil.getDayStart(t);
result.add(DateFormat.formatToDateStr(normalized));
break;
case 4:
normalized = TimeUtil.getWeekStart(t);
result.add(DateFormat.formatToDateStr(normalized));
break;
case 5:
normalized = TimeUtil.getMonthStart(t);
result.add(DateFormat.formatToDateStr(normalized));
break;
case 6:
normalized = TimeUtil.getQuarterStart(t);
result.add(DateFormat.formatToDateStr(normalized));
break;
case 7:
normalized = TimeUtil.getYearStart(t);
result.add(DateFormat.formatToDateStr(normalized));
break;
default:
代码示例来源:origin: apache/kylin
private static String datePlus(String date, int plusDays) {
long millis = DateFormat.stringToMillis(date);
millis += (1000L * 3600L * 24L) * plusDays;
return DateFormat.formatToDateStr(millis);
}
代码示例来源: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 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: apache/kylin
public void encodeDecode(String origin) {
long a = encode(origin);
String back = decode(a);
String originChoppingMilis = DateFormat.formatToTimeWithoutMilliStr(DateFormat.stringToMillis(origin));
String backMillis = DateFormat.formatToTimeWithoutMilliStr(Long.parseLong(back));
Assert.assertEquals(originChoppingMilis, backMillis);
}
代码示例来源:origin: apache/kylin
public void test1() throws Exception {
System.out.println(org.apache.kylin.common.util.DateFormat.formatToTimeStr(1433833611000L));
System.out.println(org.apache.kylin.common.util.DateFormat.formatToTimeStr(1433250517000L));
System.out.println(org.apache.kylin.common.util.DateFormat.stringToMillis("2015-06-01 00:00:00"));
System.out.println(org.apache.kylin.common.util.DateFormat.stringToMillis("2015-05-15 17:00:00"));
代码示例来源: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);
return new BigDecimal(strValue);
} else if ("timestamp".equals(dataType)) {
return Long.valueOf(DateFormat.stringToMillis(strValue));
} else if ("float".equals(dataType)) {
return Float.valueOf(strValue);
代码示例来源:origin: apache/kylin
private String formatTime(String dateStr, DataType dataType) {
if (dataType.isDatetime() || dataType.isTime()) {
throw new RuntimeException("Datetime and time type are not supported yet");
}
if (DateFormat.isSupportedDateFormat(dateStr)) {
return dateStr;
}
long millis = Long.parseLong(dateStr);
if (dataType.isTimestamp()) {
return DateFormat.formatToTimeStr(millis);
} else if (dataType.isDate()) {
return DateFormat.formatToDateStr(millis);
} else {
throw new RuntimeException("Unknown type " + dataType + " to formatTime");
}
}
}
代码示例来源:origin: apache/kylin
@Override
public String next() {
if (type.isStringFamily()) {
// string
return format.replace(ColumnGenConfig.$RANDOM, "" + randomInt());
} else if (type.isTimeFamily()) {
// time
return DateFormat.formatToTimeStr(randomMillis(), format);
} else if (type.isDateTimeFamily()) {
// date
return DateFormat.formatToDateStr(randomMillis(), format);
} else if (type.isIntegerFamily()) {
// integer
return formatNumber(randomInt());
} else if (type.isNumberFamily()) {
// double
return formatNumber(randomDouble());
} else {
throw new IllegalStateException();
}
}
代码示例来源:origin: apache/kylin
public DateTimeParser(Map<String, String> properties) {
super(properties);
tsPattern = properties.get(StreamingParser.PROPERTY_TS_PATTERN);
try {
formatter = org.apache.kylin.common.util.DateFormat.getDateFormat(tsPattern);
} catch (Throwable e) {
throw new IllegalStateException("Invalid tsPattern: '" + tsPattern + "'.");
}
}
代码示例来源:origin: apache/kylin
public static Date stringToDate(String str) {
return stringToDate(str, DEFAULT_DATE_PATTERN);
}
代码示例来源:origin: apache/kylin
@Override
public String toString() {
return "BadQueryEntry [ adj=" + adj + ", server=" + server + ", startTime=" + DateFormat.formatToTimeStr(startTime) + " ]";
}
}
代码示例来源:origin: apache/kylin
@Override
final protected String getValueFromIdImpl(int id) {
if (id < baseId || id > maxId)
throw new IllegalArgumentException("ID '" + id + "' is out of range [" + baseId + "," + maxId + "]");
long millis = DateDimEnc.getMillisFromNumOfDaysSince0000(calcSeqNoFromId(id));
return dateToString(new Date(millis), pattern);
}
代码示例来源: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: apache/kylin
/**
*
* @param id
* @return return like "0000001430812800000"
*/
@Override
protected String getValueFromIdImpl(int id) {
if (id == nullId())
return null;
long millis = 1000L * id;
return DateFormat.formatToTimeWithoutMilliStr(millis);
}
代码示例来源:origin: org.apache.kylin/kylin-core-cube
private static String datePlus(String date, int plusDays) {
long millis = DateFormat.stringToMillis(date);
millis += (1000L * 3600L * 24L) * plusDays;
return DateFormat.formatToDateStr(millis);
}
代码示例来源:origin: apache/kylin
public void encodeDecode(String origin) {
int a = dict.getIdFromValue(origin);
String back = dict.getValueFromId(a);
String originChoppingMilis = DateFormat.formatToTimeWithoutMilliStr(DateFormat.stringToMillis(origin));
Assert.assertEquals(originChoppingMilis, back);
}
代码示例来源:origin: org.apache.kylin/kylin-core-metadata
private String formatTime(String dateStr, DataType dataType) {
if (dataType.isDatetime() || dataType.isTime()) {
throw new RuntimeException("Datetime and time type are not supported yet");
}
if (DateFormat.isSupportedDateFormat(dateStr)) {
return dateStr;
}
long millis = Long.parseLong(dateStr);
if (dataType.isTimestamp()) {
return DateFormat.formatToTimeStr(millis);
} else if (dataType.isDate()) {
return DateFormat.formatToDateStr(millis);
} else {
throw new RuntimeException("Unknown type " + dataType + " to formatTime");
}
}
}
内容来源于网络,如有侵权,请联系作者删除!