当前位置: 首页>>代码示例>>Java>>正文


Java DateTimeFormat.forPattern方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:21,代码来源:QueryTest.java

示例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();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:25,代码来源:TestNewDateFunctions.java

示例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);
            
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:21,代码来源:TestJoda.java

示例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);
}
 
开发者ID:yu-iskw,项目名称:google-log-aggregation-example,代码行数:18,代码来源:TableNameByWindowFnTest.java

示例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;
    }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:14,代码来源:DateUtility.java

示例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;
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:11,代码来源:JournalViewActivity.java

示例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));
		
	}
}
 
开发者ID:onsoul,项目名称:os,代码行数:35,代码来源:BillNoUtils.java

示例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));
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:29,代码来源:FieldConstraintsTest.java

示例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);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:8,代码来源:RegexExtractorInterceptorMillisSerializer.java

示例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();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:37,代码来源:RoomController.java

示例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();
    } 
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:15,代码来源:TypeInferrer.java

示例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;
    }
 
开发者ID:d2si-oss,项目名称:ooso,代码行数:31,代码来源:Mapper.java

示例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);
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:6,代码来源:GlucoseAlert.java

示例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();
}
 
开发者ID:jeikerxiao,项目名称:X-mall,代码行数:6,代码来源:DateTimeUtil.java

示例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();
}
 
开发者ID:prb8025236,项目名称:CheapStore,代码行数:6,代码来源:DateTimeUtil.java


注:本文中的org.joda.time.format.DateTimeFormat.forPattern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。