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


Java DateTimeFormat类代码示例

本文整理汇总了Java中org.joda.time.format.DateTimeFormat的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormat类的具体用法?Java DateTimeFormat怎么用?Java DateTimeFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DateTimeFormat类属于org.joda.time.format包,在下文中一共展示了DateTimeFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dateSearchBraces

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
@Test
 public void dateSearchBraces() throws IOException, SqlParseException, SQLFeatureNotSupportedException, ParseException {
     DateTimeFormatter formatter = DateTimeFormat.forPattern(TS_DATE_FORMAT);
     DateTime dateToCompare = new DateTime(2015, 3, 15, 0, 0, 0);

     SearchHits response = query(String.format("SELECT odbc_time FROM %s/odbc WHERE odbc_time < {ts '2015-03-15 00:00:00.000'}", TEST_INDEX));
     SearchHit[] hits = response.getHits();
     for(SearchHit hit : hits) {
         Map<String, Object> source = hit.getSource();
String insertTimeStr = (String) source.get("odbc_time");
insertTimeStr = insertTimeStr.replace("{ts '", "").replace("'}", "");

         DateTime insertTime = formatter.parseDateTime(insertTimeStr);

         String errorMessage = String.format("insert_time must be smaller then 2015-03-15. found: %s", insertTime);
         Assert.assertTrue(errorMessage, insertTime.isBefore(dateToCompare));
     }
 }
 
开发者ID:mazhou,项目名称:es-sql,代码行数:19,代码来源:QueryTest.java

示例2: getSingleItemDescription

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
@Override
protected String getSingleItemDescription(String expression) {
    String exp = expression;
    if (expression.contains("#")) {
        exp = expression.substring(0, expression.indexOf("#"));
    } else if (expression.contains("L")) {
        exp = exp.replace("L", "");
    }
    if (StringUtils.isNumeric(exp)) {
        int dayOfWeekNum = Integer.parseInt(exp);
        boolean isZeroBasedDayOfWeek = (options == null || options.isZeroBasedDayOfWeek());
        boolean isInvalidDayOfWeekForSetting = (options != null && !options.isZeroBasedDayOfWeek() && dayOfWeekNum <= 1);
        if (isInvalidDayOfWeekForSetting || (isZeroBasedDayOfWeek && dayOfWeekNum == 0)) {
            return DateAndTimeUtils.getDayOfWeekName(7);
        } else if (options != null && !options.isZeroBasedDayOfWeek()) {
            dayOfWeekNum -= 1;
        }
        return DateAndTimeUtils.getDayOfWeekName(dayOfWeekNum);
    } else {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("EEE").withLocale(Locale.ENGLISH);
        return dateTimeFormatter.parseDateTime(WordUtils.capitalizeFully(exp)).dayOfWeek().getAsText(I18nMessages.getCurrentLocale());
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:24,代码来源:DayOfWeekDescriptionBuilder.java

示例3: getDaysBetween

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
public static int getDaysBetween(final String date1, final String date2, String format){
    try {
        final DateTimeFormatter fmt =
                DateTimeFormat
                        .forPattern(format)
                        .withChronology(
                                LenientChronology.getInstance(
                                        GregorianChronology.getInstance()));
        return Days.daysBetween(
                fmt.parseDateTime(date1),
                fmt.parseDateTime(date2)
        ).getDays();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例4: onCreate

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    route = (Route) getIntent().getSerializableExtra("route");
    this.mShowDividers = false;

    super.onCreate(savedInstanceState);

    setTitle(route.getDepartureStation().getLocalizedName() + " - " + route.getArrivalStation().getLocalizedName());

    DateTimeFormatter df = DateTimeFormat.forPattern(getString(warning_not_realtime_datetime));
    setSubTitle(df.print(route.getDepartureTime()));

    // disable pull-to-refresh
    // TODO: support refreshing
    this.vRefreshLayout.setEnabled(false);

    this.vWarningNotRealtime.setVisibility(View.GONE);
}
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:19,代码来源:RouteDetailActivity.java

示例5: testCreateIndexWithDateMathExpression

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
public void testCreateIndexWithDateMathExpression() throws Exception {
    DateTime now = new DateTime(DateTimeZone.UTC);
    String index1 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now);
    String index2 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(1));
    String index3 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(2));

    String dateMathExp1 = "<.marvel-{now/d}>";
    String dateMathExp2 = "<.marvel-{now/d-1d}>";
    String dateMathExp3 = "<.marvel-{now/d-2d}>";
    createIndex(dateMathExp1, dateMathExp2, dateMathExp3);


    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings(index1, index2, index3).get();
    assertEquals(dateMathExp1, getSettingsResponse.getSetting(index1, IndexMetaData.SETTING_INDEX_PROVIDED_NAME));
    assertEquals(dateMathExp2, getSettingsResponse.getSetting(index2, IndexMetaData.SETTING_INDEX_PROVIDED_NAME));
    assertEquals(dateMathExp3, getSettingsResponse.getSetting(index3, IndexMetaData.SETTING_INDEX_PROVIDED_NAME));

    ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
    assertThat(clusterState.metaData().index(index1), notNullValue());
    assertThat(clusterState.metaData().index(index2), notNullValue());
    assertThat(clusterState.metaData().index(index3), notNullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateMathIndexExpressionsIntegrationIT.java

示例6: getVersionInfo

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
private VersionInfo getVersionInfo() {
  String version = DremioVersionInfo.getVersion(); // get dremio version (x.y.z)
  long buildTime = 0;
  CommitInfo commitInfo = null;

  try {
    URL u = Resources.getResource("git.properties");

    if (u != null) {
      Properties p = new Properties();
      p.load(Resources.asByteSource(u).openStream());
      buildTime = DateTime.parse(p.getProperty("git.build.time"), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ")).getMillis();
      commitInfo = new CommitInfo(
        p.getProperty("git.commit.id"),
        p.getProperty("git.build.user.email"),
        DateTime.parse(p.getProperty("git.commit.time"), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ")).getMillis(),
        p.getProperty("git.commit.message.short"));
    }
  } catch (Exception e) {
    logger.warn("Failure when trying to access and parse git.properties.", e);
  }
  return new VersionInfo(version, buildTime, commitInfo);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:IndexServlet.java

示例7: testAddJob

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
@Test
public void testAddJob()
{
	ScheduleJobEntity job = new ScheduleJobEntity();
	job.setJobName("test");
	job.setJobGroup("test");
	job.setCronExpression("*/5 * * * * ?");
	job.setJobClassName("com.webside.quartz.job.EmailJob");
	//java 8 实现方式
	//LocalDate localDate = LocalDate.parse("2016-07-16 15:23:43",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
	//Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
	//joda实现方式
	LocalDate localDate = LocalDate.parse("2016-07-16 15:23:43", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
	Date date = localDate.toDate();
	job.setStartDate(date);
	job.setEndDate(localDate.plusDays(10).toDate());
	scheduleJobService.addJob(job);
	
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:20,代码来源:QuartzTest.java

示例8: testExpression_CustomTimeZoneInIndexName

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
public void testExpression_CustomTimeZoneInIndexName() throws Exception {
    DateTimeZone timeZone;
    int hoursOffset;
    int minutesOffset = 0;
    if (randomBoolean()) {
        hoursOffset = randomIntBetween(-12, 14);
        timeZone = DateTimeZone.forOffsetHours(hoursOffset);
    } else {
        hoursOffset = randomIntBetween(-11, 13);
        minutesOffset = randomIntBetween(0, 59);
        timeZone = DateTimeZone.forOffsetHoursMinutes(hoursOffset, minutesOffset);
    }
    DateTime now;
    if (hoursOffset >= 0) {
        // rounding to next day 00:00
        now = DateTime.now(UTC).plusHours(hoursOffset).plusMinutes(minutesOffset).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    } else {
        // rounding to today 00:00
        now = DateTime.now(UTC).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    }
    Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis());
    List<String> results = expressionResolver.resolve(context, Arrays.asList("<.marvel-{now/d{YYYY.MM.dd|" + timeZone.getID() + "}}>"));
    assertThat(results.size(), equalTo(1));
    logger.info("timezone: [{}], now [{}], name: [{}]", timeZone, now, results.get(0));
    assertThat(results.get(0), equalTo(".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.withZone(timeZone))));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:DateMathExpressionResolverTests.java

示例9: 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

示例10: parse2DateTime

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
/**
 * <p>将字符串格式的日期转换为@{org.joda.time.DateTime}</p>
 * 
 * @param dateTimeText		- 日期字符串形式的值
 * @param pattern			- 针对dateTimeText的日期格式
 * @return
 */
public static DateTime parse2DateTime(String dateTimeText, String pattern){
	Assert.hasText(dateTimeText, "Parameter 'dateTimeText' can not be empty!");
	Assert.hasText(dateTimeText, "Parameter 'pattern' can not be empty!");
	String format = pattern;
	String text = dateTimeText;
	Matcher matcher = null;
	String suffix = ".SSS";
	//dateTimeText以毫秒结尾 && 格式pattern中没有以.SSS结尾
	if((matcher = TIMESTAMP_MSEC_REGEX_PATTERN.matcher(dateTimeText)).find() && matcher.end() == dateTimeText.length() && !pattern.endsWith(suffix)){
		format = format + suffix;
	//dateTimeText没有以毫秒结尾 && 格式pattern中以.SSS结尾
	}else if((matcher = TIMESTAMP_REGEX_PATTERN.matcher(dateTimeText)).find() && matcher.end() == dateTimeText.length() && pattern.endsWith(suffix)){
		text = text + ".0";
	}
	return DateTimeFormat.forPattern(format).parseDateTime(text);
}
 
开发者ID:penggle,项目名称:xproject,代码行数:24,代码来源:DateTimeUtils.java

示例11: TikaPoweredMetadataExtracter

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
public TikaPoweredMetadataExtracter(String extractorContext, HashSet<String> supportedMimeTypes, HashSet<String> supportedEmbedMimeTypes)
{
    super(supportedMimeTypes, supportedEmbedMimeTypes);

    this.extractorContext = extractorContext;

    // TODO Once TIKA-451 is fixed this list will get nicer
    DateTimeParser[] parsersUTC = {
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").getParser(),
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser()
    };
    DateTimeParser[] parsers = {
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(),
        DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
        DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").getParser(),
        DateTimeFormat.forPattern("yyyy/MM/dd").getParser(),
            DateTimeFormat.forPattern("EEE MMM dd hh:mm:ss zzz yyyy").getParser()
    };

    this.tikaUTCDateFormater = new DateTimeFormatterBuilder().append(null, parsersUTC).toFormatter().withZone(DateTimeZone.UTC);
    this.tikaDateFormater = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:TikaPoweredMetadataExtracter.java

示例12: 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

示例13: getHoursBetween

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
public static int getHoursBetween(final String date1, final String date2, String format){
    try {
    final DateTimeFormatter fmt =
            DateTimeFormat
                    .forPattern(format)
                    .withChronology(
                            LenientChronology.getInstance(
                                    GregorianChronology.getInstance()));
    return Hours.hoursBetween(
            fmt.parseDateTime(date1),
            fmt.parseDateTime(date2)
    ).getHours();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例14: convert

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
private BitcoinCurse convert(Response raw) {
  final Double coin = 1d;
  Double euro = 0d;

  Matcher matcher = MONEY_PATTERN.matcher(raw.price_eur);
  if(matcher.find()) {
    final String rawEuro = matcher.group(1)
        .replace(".", ";")
        .replace(",", ".")
        .replace(";", "");

    euro = Double.parseDouble(rawEuro);
  }

  final DateTime date = DateTimeFormat.forPattern("dd.MM.yy HH:mm").parseDateTime(raw.date_de);

  return new BitcoinCurse(date, coin, euro);
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:19,代码来源:RestCurseProvider.java

示例15: create

import org.joda.time.format.DateTimeFormat; //导入依赖的package包/类
public void create(String title, File imgsDir, File output) throws IOException {
    timestamp = DateTimeFormat.forPattern("yyyy-MM-dd'T'hh:mm:ssSZZ").print(DateTime.now());
    uuid = UUID.randomUUID().toString();
    this.title = title;
    this.imgsDir = imgsDir;

    try {
        basedir = File.createTempFile(uuid,"");
        basedir.delete();
        basedir.mkdirs();
    } catch (IOException e) {
        e.printStackTrace();
    }
    classLoader = getClass().getClassLoader();

    copyImages();
    copyStandardFilez();
    createOPFFile();
    createIndex();
    createTitlePage();
    createTOC();
    pack(basedir.getAbsolutePath(), output.getAbsolutePath());
    FileUtils.deleteDirectory(basedir);
}
 
开发者ID:jmrozanec,项目名称:pdf-converter,代码行数:25,代码来源:EpubCreator.java


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