本文整理汇总了Java中org.joda.time.format.DateTimeFormat.forPattern方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormat.forPattern方法的具体用法?Java DateTimeFormat.forPattern怎么用?Java DateTimeFormat.forPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.format.DateTimeFormat
的用法示例。
在下文中一共展示了DateTimeFormat.forPattern方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dateBetweenSearch
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Test
public void dateBetweenSearch() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);
DateTime dateLimit1 = new DateTime(2014, 8, 18, 0, 0, 0);
DateTime dateLimit2 = new DateTime(2014, 8, 21, 0, 0, 0);
SearchHits response = query(String.format("SELECT insert_time FROM %s/online WHERE insert_time BETWEEN '2014-08-18' AND '2014-08-21' LIMIT 3", TEST_INDEX));
SearchHit[] hits = response.getHits();
for(SearchHit hit : hits) {
Map<String, Object> source = hit.getSource();
DateTime insertTime = formatter.parseDateTime((String) source.get("insert_time"));
boolean isBetween =
(insertTime.isAfter(dateLimit1) || insertTime.isEqual(dateLimit1)) &&
(insertTime.isBefore(dateLimit2) || insertTime.isEqual(dateLimit2));
Assert.assertTrue("insert_time must be between 2014-08-18 and 2014-08-21", isBetween);
}
}
示例2: testUnixTimeStampForDateWithPattern
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Test
public void testUnixTimeStampForDateWithPattern() throws Exception {
formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
date = formatter.parseDateTime("2009-03-20 11:30:01.0");
unixTimeStamp = date.getMillis() / 1000;
testBuilder()
.sqlQuery("select unix_timestamp('2009-03-20 11:30:01.0', 'yyyy-MM-dd HH:mm:ss.SSS') from cp.`employee.json` limit 1")
.ordered()
.baselineColumns("EXPR$0")
.baselineValues(unixTimeStamp)
.build().run();
formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
date = formatter.parseDateTime("2009-03-20");
unixTimeStamp = date.getMillis() / 1000;
testBuilder()
.sqlQuery("select unix_timestamp('2009-03-20', 'yyyy-MM-dd') from cp.`employee.json` limit 1")
.ordered()
.baselineColumns("EXPR$0")
.baselineValues(unixTimeStamp)
.build().run();
}
示例3: testJoda
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Test
public void testJoda()
{
DateTimeFormatter format = DateTimeFormat .forPattern("yyyy-MM-dd HH:mm:ss");
//时间解析
DateTime dateTime2 = DateTime.parse("2012-12-21 23:22:45", format);
//时间格式化,输出==> 2012/12/21 23:22:45 Fri
String string_u = dateTime2.toString("yyyy/MM/dd HH:mm:ss EE");
System.out.println(string_u);
//格式化带Locale,输出==> 2012年12月21日 23:22:45 星期五
String string_c = dateTime2.toString("yyyy年MM月dd日 HH:mm:ss EE",Locale.CHINESE);
System.out.println(string_c);
LocalDate date = LocalDate.parse("2012-12-21 23:22:45", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
Date dates = date.toDate();
System.out.println(dates);
}
示例4: testApply
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Test
public void testApply() {
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
Instant start = format.parseDateTime("2017-01-01 00:00:00").toInstant();
Instant end = format.parseDateTime("2017-01-01 00:01:00").toInstant();
IntervalWindow window = new IntervalWindow(start, end);
String projectId = "testProject_id";
String datasetId = "testDatasetId";
String tablePrefix = "testTablePrefix";
TableNameByWindowFn fn = new TableNameByWindowFn(projectId, datasetId, tablePrefix);
String result = fn.apply(window);
String expected = new Formatter()
.format("%s:%s.%s_%s", projectId, datasetId, tablePrefix, "20170101")
.toString();
assertEquals(expected, result);
}
示例5: getDateTimeFormatter
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public static DateTimeFormatter getDateTimeFormatter() {
if (dateTimeTZFormat == null) {
DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser();
dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
}
return dateTimeTZFormat;
}
示例6: createFileName
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
private File createFileName(String prefix, String ext) throws
IOException {
DateTime now = DateTime.now();
DateTimeFormatter fmt = DateTimeFormat.forPattern
("yyyyMMdd-HHmmss");
File cacheDir = getExternalCacheDir();
File media = File.createTempFile(prefix + "-" + fmt.print(now),
ext, cacheDir);
return media;
}
示例7: main
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public static void main(String[] args) throws NoSuchAlgorithmException {
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
for (int i=1; i<=1440; i++) {
System.out.println("maps.put(\"20141109-"+i+"\", \""+sr.nextInt(10)+" "+sr.nextInt(10)+" "+sr.nextInt(10)+" "+sr.nextInt(10)+" "+sr.nextInt(10)+"\");");
}
System.out.println(LocalDate.now());
Instant in = new Instant(1414508801016L);
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
formatter=formatter.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+8")));
in = in.plus(100);
System.out.println(in.get(DateTimeFieldType.millisOfSecond()));
System.out.println(in.toDate());
System.out.println(formatter.print(in));
System.out.println(in.getMillis());
Pattern pattern = Pattern.compile("\"phase\":\"20141018023\"(.*)\"data\":\\[\"(\\d)\",\"(\\d)\",\"(\\d)\",\"(\\d)\",\"(\\d)\"\\]\\}\\]\\}");
Matcher matcher = pattern.matcher("{\"code\":0,\"message\":\"\",\"data\":[{\"phasetype\":200,\"phase\":\"20141018023\",\"create_at\":\"2014-01-21 14:41:05\",\"time_startsale\":\"2014-10-18 01:50:00\",\"time_endsale\":\"2014-10-18 01:55:00\",\"time_endticket\":\"2014-10-18 01:55:00\",\"time_draw\":\"2014-10-18 01:56:00\",\"status\":5,\"forsale\":0,\"is_current\":0,\"result\":{\"result\":[{\"key\":\"ball\",\"data\":[\"1\",\"5\",\"0\",\"5\",\"9\"]}]},\"result_detail\":{\"resultDetail\":[{\"key\":\"prize1\",\"bet\":\"0\",\"prize\":100000},{\"key\":\"prize2\",\"bet\":\"0\",\"prize\":20000},{\"key\":\"prize3\",\"bet\":\"0\",\"prize\":200},{\"key\":\"prize4\",\"bet\":\"0\",\"prize\":20},{\"key\":\"prize5\",\"bet\":\"0\",\"prize\":1000},{\"key\":\"prize6\",\"bet\":\"0\",\"prize\":320},{\"key\":\"prize7\",\"bet\":\"0\",\"prize\":160},{\"key\":\"prize8\",\"bet\":\"0\",\"prize\":100},{\"key\":\"prize9\",\"bet\":\"0\",\"prize\":50},{\"key\":\"prize10\",\"bet\":\"0\",\"prize\":10},{\"key\":\"prize11\",\"bet\":\"0\",\"prize\":4}]},\"pool_amount\":\"\",\"sale_amount\":\"\",\"ext\":\"\",\"fc3d_sjh\":null,\"terminal_status\":2,\"fordraw\":0,\"time_startsale_fixed\":\"2014-10-18 01:47:40\",\"time_endsale_fixed\":\"2014-10-18 01:52:40\",\"time_endsale_syndicate_fixed\":\"2014-10-18 01:55:00\",\"time_endsale_upload_fixed\":\"2014-10-18 01:55:00\",\"time_draw_fixed\":\"2014-10-18 01:56:00\",\"time_startsale_correction\":140,\"time_endsale_correction\":140,\"time_endsale_syndicate_correction\":0,\"time_endsale_upload_correction\":0,\"time_draw_correction\":0,\"time_exchange\":\"2014-12-16 01:56:00\"},{\"phasetype\":\"200\",\"phase\":\"20141018024\",\"create_at\":\"2014-01-21 14:41:05\",\"time_startsale\":\"2014-10-18 01:55:00\",\"time_endsale\":\"2014-10-18 10:00:00\",\"time_endticket\":\"2014-10-18 10:00:00\",\"time_draw\":\"2014-10-18 10:01:00\",\"status\":\"2\",\"forsale\":\"1\",\"is_current\":\"1\",\"result\":null,\"result_detail\":null,\"pool_amount\":\"\",\"sale_amount\":\"\",\"ext\":\"\",\"fc3d_sjh\":null,\"terminal_status\":\"1\",\"fordraw\":\"0\",\"time_startsale_fixed\":\"2014-10-18 01:52:40\",\"time_endsale_fixed\":\"2014-10-18 09:57:40\",\"time_endsale_syndicate_fixed\":\"2014-10-18 10:00:00\",\"time_endsale_upload_fixed\":\"2014-10-18 10:00:00\",\"time_draw_fixed\":\"2014-10-18 10:01:00\",\"time_startsale_correction\":140,\"time_endsale_correction\":140,\"time_endsale_syndicate_correction\":0,\"time_endsale_upload_correction\":0,\"time_draw_correction\":0,\"time_exchange\":\"2014-12-16 10:01:00\"}],\"redirect\":\"\",\"datetime\":\"2014-10-18 04:08:45\",\"timestamp\":1413576525}");
//Pattern pattern = Pattern.compile("(.*)message(\\d\\d)(\\d)(\\d)(\\d)");
//Matcher matcher = pattern.matcher("23fawef_message12345");
//Pattern pattern = Pattern.compile("\"number\":\"(\\d) (\\d) (\\d) (\\d) (\\d)\",\"period\":\"20141017083");
//Matcher matcher = pattern.matcher("{\"latestPeriods\":[{\"number\":\"6 0 2 2 1\",\"period\":\"20141017084\"},{\"number\":\"0 8 9 1 9\",\"period\":\"20141017083\"},{\"number\":\"4 0 4 4 6\",\"period\":\"20141017082\"},{\"number\":\"4 5 8 7 7\",\"period\":\"20141017081\"},{\"number\":\"7 2 8 5 3\",\"period\":\"20141017080\"},{\"number\":\"9 7 3 8 0\",\"period\":\"20141017079\"},{\"number\":\"3 7 6 0 1\",\"period\":\"20141017078\"},{\"number\":\"9 6 4 8 5\",\"period\":\"20141017077\"},{\"number\":\"6 4 1 8 1\",\"period\":\"20141017076\"},{\"number\":\"9 5 2 8 7\",\"period\":\"20141017075\"}],\"successful\":\"true\",\"statusDesc\":\"获取数据成功\"}");
matcher.find();
for (int i=1; i<=matcher.groupCount(); i++) {
System.out.println(matcher.group(i));
}
}
示例8: testEnumDatetime
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Test
public void testEnumDatetime(){
Map<String, Object> violatedConstraints = null;
Map<String, Object> constraints = new HashMap();
List<DateTime> enumDatetimes = new ArrayList();
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
DateTime datetime1 = formatter.parseDateTime("2000-01-15T13:44:33.000Z");
enumDatetimes.add(datetime1);
DateTime datetime2 = formatter.parseDateTime("2019-01-15T13:44:33.000Z");
enumDatetimes.add(datetime2);
constraints.put(Field.CONSTRAINT_KEY_ENUM, enumDatetimes);
Field field = new Field("test", Field.FIELD_TYPE_DATETIME, null, null, null, constraints);
violatedConstraints = field.checkConstraintViolations(datetime1);
Assert.assertTrue(violatedConstraints.isEmpty());
violatedConstraints = field.checkConstraintViolations(datetime2);
Assert.assertTrue(violatedConstraints.isEmpty());
DateTime datetime3 = formatter.parseDateTime("2003-01-15T13:44:33.000Z");
violatedConstraints = field.checkConstraintViolations(datetime3);
Assert.assertTrue(violatedConstraints.containsKey(Field.CONSTRAINT_KEY_ENUM));
}
示例9: configure
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Override
public void configure(Context context) {
String pattern = context.getString("pattern");
Preconditions.checkArgument(!StringUtils.isEmpty(pattern),
"Must configure with a valid pattern");
formatter = DateTimeFormat.forPattern(pattern);
}
示例10: updateExamStartingHours
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
@Restrict(@Group({"ADMIN"}))
public Result updateExamStartingHours() {
JsonNode root = request().body().asJson();
List<Long> roomIds = new ArrayList<>();
for (JsonNode roomId : root.get("roomIds")) {
roomIds.add(roomId.asLong());
}
List<ExamRoom> rooms = Ebean.find(ExamRoom.class).where().idIn(roomIds).findList();
for (ExamRoom examRoom : rooms) {
if (examRoom == null) {
return notFound();
}
List<ExamStartingHour> previous = Ebean.find(ExamStartingHour.class)
.where().eq("room.id", examRoom.getId()).findList();
Ebean.deleteAll(previous);
JsonNode node = request().body().asJson();
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.yyyy HH:mmZZ");
for (JsonNode hours : node.get("hours")) {
ExamStartingHour esh = new ExamStartingHour();
esh.setRoom(examRoom);
// Deliberately use first/second of Jan to have no DST in effect
DateTime startTime = DateTime.parse(hours.asText(), formatter).withDayOfYear(1);
esh.setStartingHour(startTime.toDate());
esh.setTimezoneOffset(DateTimeZone.forID(examRoom.getLocalTimezone()).getOffset(startTime));
esh.save();
}
asyncUpdateRemote(examRoom);
}
return ok();
}
示例11: castYearmonth
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public DateTime castYearmonth(String format, String value, Map<String, Object> options) throws TypeInferringException{
Pattern pattern = Pattern.compile(REGEX_YEARMONTH);
Matcher matcher = pattern.matcher(value);
if(matcher.matches()){
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM");
DateTime dt = formatter.parseDateTime(value);
return dt;
}else{
throw new TypeInferringException();
}
}
示例12: map
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public String map(BufferedReader objectBufferedReader) {
try {
Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
Map<String, Long> result = new HashMap<>();
String line;
while (((line = objectBufferedReader.readLine()) != null)) {
Record currentRecord = new Record(line);
String key = String.join(
"-",
currentRecord.getPassengerCount(),
String.valueOf(dateTimeFormatter.parseDateTime(currentRecord.getTpepPickupDatetime()).getYear()),
String.valueOf(Double.valueOf(currentRecord.getTripDistance()).intValue()));
Long count = result.get(key);
result.put(key, count == null ? 1 : count + 1);
}
return gson.toJson(result);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例13: getDate
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public String getDate() {
DateTime date = new DateTime(timestamp);
DateTimeFormatter dtf = DateTimeFormat.forPattern("kk:mm dd/MM/yyyy");
return date.toString(dtf);
}
示例14: strToDate
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public static Date strToDate(String dateTimeStr, String formatStr) {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
示例15: strToDate
import org.joda.time.format.DateTimeFormat; //导入方法依赖的package包/类
public static Date strToDate(String dateTimeStr){
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDARD_FORMAT);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}