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


Java DateTimeFormatter.print方法代码示例

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


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

示例1: testDate

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public void testDate() throws Exception {
    assertResult("{'date':null}", () -> builder().startObject().field("date", (Date) null).endObject());
    assertResult("{'date':null}", () -> builder().startObject().field("date").value((Date) null).endObject());

    final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
    assertResult("{'d1':'2016-01-01T00:00:00.000Z'}", () -> builder().startObject().field("d1", d1).endObject());
    assertResult("{'d1':'2016-01-01T00:00:00.000Z'}", () -> builder().startObject().field("d1").value(d1).endObject());

    final Date d2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC).toDate();
    assertResult("{'d2':'2016-12-25T07:59:42.213Z'}", () -> builder().startObject().field("d2", d2).endObject());
    assertResult("{'d2':'2016-12-25T07:59:42.213Z'}", () -> builder().startObject().field("d2").value(d2).endObject());

    final DateTimeFormatter formatter = randomFrom(ISODateTimeFormat.basicDate(), ISODateTimeFormat.dateTimeNoMillis());
    final Date d3 = DateTime.now().toDate();

    String expected = "{'d3':'" + formatter.print(d3.getTime()) + "'}";
    assertResult(expected, () -> builder().startObject().field("d3", d3, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("d3").value(d3, formatter).endObject());

    expectNonNullFormatterException(() -> builder().startObject().field("d3", d3, null).endObject());
    expectNonNullFormatterException(() -> builder().startObject().field("d3").value(d3, null).endObject());
    expectNonNullFormatterException(() -> builder().value(null, 1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:BaseXContentTestCase.java

示例2: getReportTableStartTime

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private String getReportTableStartTime(JSONObject jsonObject, String endTime)
    throws ParseException {
  switch (jsonObject.getString(QueryHelper.PERIODICITY)) {
    case QueryHelper.PERIODICITY_MONTH:
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
      Calendar toDate = new GregorianCalendar();
      toDate.setTime(format.parse(endTime));
      toDate.add(Calendar.MONTH, -1*(QueryHelper.MONTHS_LIMIT-1));
      return format.format(toDate.getTime());
    case QueryHelper.PERIODICITY_WEEK:
      DateTimeFormatter mDateTimeFormatter = DateTimeFormat.forPattern(
          QueryHelper.DATE_FORMAT_DAILY);
      DateTime toTime = mDateTimeFormatter.parseDateTime(endTime);
      return mDateTimeFormatter.print(toTime.minusWeeks(QueryHelper.WEEKS_LIMIT-1));
    default:
      mDateTimeFormatter = DateTimeFormat.forPattern(QueryHelper.DATE_FORMAT_DAILY);
      toTime = mDateTimeFormatter.parseDateTime(endTime);
      return mDateTimeFormatter.print(toTime.minusDays(QueryHelper.DAYS_LIMIT-1));
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:ReportPluginService.java

示例3: onDateTimePicked

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Override
public void onDateTimePicked(DateTime d) {
    searchDateTime = d;

    DateTime now = new DateTime();

    DateTimeFormatter df = DateTimeFormat.forPattern("dd MMMM yyyy");
    DateTimeFormatter tf = DateTimeFormat.forPattern("HH:mm");

    String day = df.print(searchDateTime);
    String time = tf.print(searchDateTime);
    String at = getActivity().getResources().getString(R.string.time_at);

    if (now.get(DateTimeFieldType.year()) == searchDateTime.get(DateTimeFieldType.year())) {
        if (now.get(DateTimeFieldType.dayOfYear()) == searchDateTime.get(DateTimeFieldType.dayOfYear())) {
            day = getActivity().getResources().getString(R.string.time_today);
        } else  //noinspection RedundantCast
            if (now.get(DateTimeFieldType.dayOfYear()) + 1 == (int) searchDateTime.get(DateTimeFieldType.dayOfYear())) {
                day = getActivity().getResources().getString(R.string.time_tomorrow);
            }
    }
    vDatetime.setText(day + " " + at + " " + time);
}
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:24,代码来源:RouteSearchFragment.java

示例4: getExecCommandForHeapDump

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Generate parameters for JVM Heap dump
 *
 * @param scriptName
 * @param jvm
 * @return
 */
private ExecCommand getExecCommandForHeapDump(String scriptName, Jvm jvm) {
    final String trimmedJvmName = StringUtils.deleteWhitespace(jvm.getJvmName());

    final String jvmRootDir = Paths.get(jvm.getTomcatMedia().getRemoteDir().toString() + '/' + trimmedJvmName + '/' +
            jvm.getTomcatMedia().getRootDir()).normalize().toString();

    final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd.HHmmss");
    final String dumpFile = "heapDump." + trimmedJvmName + "." + formatter.print(DateTime.now());

    final String dumpLiveStr = ApplicationProperties.getAsBoolean(PropertyKeys.JMAP_DUMP_LIVE_ENABLED.name()) ? "live," : "\"\"";

    final String heapDumpDir = jvm.getTomcatMedia().getRemoteDir().normalize().toString() + "/" + jvm.getJvmName();

    return new ExecCommand(getFullPathScript(jvm, scriptName), jvm.getJavaHome(), heapDumpDir, dumpFile,
                           dumpLiveStr , jvmRootDir, jvm.getJvmName());
}
 
开发者ID:cerner,项目名称:jwala,代码行数:24,代码来源:JvmCommandFactory.java

示例5: getReleaseDate

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static String getReleaseDate(String date) {
        DateTimeFormatter formatter = forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withLocale(Locale.US);
//        DateTimeFormatter formatter = forPattern("yyyy-MM-dd").withLocale(Locale.US);
        LocalDate date1 = formatter.parseLocalDate(date);
        DateTimeFormatter dateTimeFormatter = forPattern("dd MMM yyyy").withLocale(Locale.US);
        return dateTimeFormatter.print(date1);
    }
 
开发者ID:prakh25,项目名称:MovieApp,代码行数:8,代码来源:Utils.java

示例6: testsTimeZoneParsing

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Test that time zones are correctly parsed. There is a bug with
 * Joda 2.9.4 (see https://github.com/JodaOrg/joda-time/issues/373)
 */
public void testsTimeZoneParsing() {
    final DateTime expected = new DateTime(2016, 11, 10, 5, 37, 59, randomDateTimeZone());

    // Formatter used to print and parse the sample date.
    // Printing the date works but parsing it back fails
    // with Joda 2.9.4
    DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ss " + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'"));

    String dateTimeAsString = formatter.print(expected);
    assertThat(dateTimeAsString, startsWith("2016-11-10T05:37:59 "));

    DateTime parsedDateTime = formatter.parseDateTime(dateTimeAsString);
    assertThat(parsedDateTime.getZone(), equalTo(expected.getZone()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TimeZoneRoundingTests.java

示例7: shouldExtractAddHeadersUsingSpecifiedSerializer

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void shouldExtractAddHeadersUsingSpecifiedSerializer()
    throws Exception {
  long now = (System.currentTimeMillis() / 60000L) * 60000L;
  String pattern = "yyyy-MM-dd HH:mm:ss,SSS";
  DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
  String body = formatter.print(now);
  System.out.println(body);
  Context context = new Context();
  // Skip the second group
  context.put(RegexExtractorInterceptor.REGEX,
      "^(\\d\\d\\d\\d-\\d\\d-\\d\\d\\s\\d\\d:\\d\\d)(:\\d\\d,\\d\\d\\d)");
  context.put(RegexExtractorInterceptor.SERIALIZERS, "s1 s2");

  String millisSerializers = RegexExtractorInterceptorMillisSerializer.class.getName();
  context.put(RegexExtractorInterceptor.SERIALIZERS + ".s1.type", millisSerializers);
  context.put(RegexExtractorInterceptor.SERIALIZERS + ".s1.name", "timestamp");
  context.put(RegexExtractorInterceptor.SERIALIZERS + ".s1.pattern", "yyyy-MM-dd HH:mm");

  // Default type
  context.put(RegexExtractorInterceptor.SERIALIZERS + ".s2.name", "data");

  fixtureBuilder.configure(context);
  Interceptor fixture = fixtureBuilder.build();

  Event event = EventBuilder.withBody(body, Charsets.UTF_8);
  Event expected = EventBuilder.withBody(body, Charsets.UTF_8);
  expected.getHeaders().put("timestamp", String.valueOf(now));
  expected.getHeaders().put("data", ":00,000");

  Event actual = fixture.intercept(event);

  Assert.assertArrayEquals(expected.getBody(), actual.getBody());
  Assert.assertEquals(expected.getHeaders(), actual.getHeaders());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:36,代码来源:TestRegexExtractorInterceptor.java

示例8: FABPressed

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@OnClick(R.id.fab)
public void FABPressed() {
    Intent result = new Intent();
    Trip aTrip = new Trip();
    aTrip.name = jname.getText().toString();
    aTrip.location = location.getText().toString();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    aTrip.startDate = fmt.print(startDate);
    aTrip.endDate = fmt.print(endDate);
    // add more code to initialize the rest of the fields
    Parcelable parcel = Parcels.wrap(aTrip);
    result.putExtra("TRIP", parcel);
    setResult(RESULT_OK, result);
    finish();
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:16,代码来源:NewJournalActivity.java

示例9: FABPressed

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@OnClick(R.id.fab)
public void FABPressed() {
    Intent result = new Intent();
    currentTrip.name = jname.getText().toString();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    currentTrip.startDate = fmt.print(startDate);
    currentTrip.endDate = fmt.print(endDate);
    // add more code to initialize the rest of the fields
    Parcelable parcel = Parcels.wrap(currentTrip);
    result.putExtra("TRIP", parcel);
    setResult(RESULT_OK, result);
    finish();
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:14,代码来源:NewJournalActivity.java

示例10: getDate

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static String getDate(String date) {
    DateTimeFormatter formatter = forPattern("yyyy-MM-dd").withLocale(Locale.US);
    LocalDate date1 = formatter.parseLocalDate(date);
    DateTimeFormatter dateTimeFormatter = forPattern("dd MMM yyyy").withLocale(Locale.US);
    return dateTimeFormatter.print(date1);
}
 
开发者ID:prakh25,项目名称:MovieApp,代码行数:7,代码来源:Utils.java

示例11: addLabel

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Override
public List<LabelPatch> addLabel(String targetCluster, String namespace, String deploymentName){
    DateTime currentTime = new DateTime();

    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH.mm.ss'Z'");

    String currentTimeString = format.print(currentTime);

    LabelPatch labelPatch = new LabelPatch();

    labelPatch.setOp("add");
    labelPatch.setPath("/metadata/labels/crashLoopDetectionTime");
    labelPatch.setValue(currentTimeString);

    List<LabelPatch> labelPatches = new ArrayList<>();
    labelPatches.add(labelPatch);

    String path = v1beta1namespacesPath + namespace + deploymentsPath + deploymentName;

    return kubernetesService.apiPatchRequest(targetCluster, path, labelPatches);
}
 
开发者ID:att,项目名称:kubekleaner,代码行数:22,代码来源:DeploymentResourceServiceImpl.java

示例12: testReadableInstant

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public void testReadableInstant() throws Exception {
    assertResult("{'instant':null}", () -> builder().startObject().field("instant", (ReadableInstant) null).endObject());
    assertResult("{'instant':null}", () -> builder().startObject().field("instant").value((ReadableInstant) null).endObject());

    final DateTime t1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);

    String expected = "{'t1':'2016-01-01T00:00:00.000Z'}";
    assertResult(expected, () -> builder().startObject().field("t1", t1).endObject());
    assertResult(expected, () -> builder().startObject().field("t1").value(t1).endObject());

    final DateTime t2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC);

    expected = "{'t2':'2016-12-25T07:59:42.213Z'}";
    assertResult(expected, () -> builder().startObject().field("t2", t2).endObject());
    assertResult(expected, () -> builder().startObject().field("t2").value(t2).endObject());

    final DateTimeFormatter formatter = randomFrom(ISODateTimeFormat.basicDate(), ISODateTimeFormat.dateTimeNoMillis());
    final DateTime t3 = DateTime.now();

    expected = "{'t3':'" + formatter.print(t3) + "'}";
    assertResult(expected, () -> builder().startObject().field("t3", t3, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("t3").value(t3, formatter).endObject());

    final DateTime t4 = new DateTime(randomDateTimeZone());

    expected = "{'t4':'" + formatter.print(t4) + "'}";
    assertResult(expected, () -> builder().startObject().field("t4", t4, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("t4").value(t4, formatter).endObject());

    long date = Math.abs(randomLong() % (2 * (long) 10e11)); // 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
    final DateTime t5 = new DateTime(date, randomDateTimeZone());

    expected = "{'t5':'" + XContentBuilder.DEFAULT_DATE_PRINTER.print(t5) + "'}";
    assertResult(expected, () -> builder().startObject().field("t5", t5).endObject());
    assertResult(expected, () -> builder().startObject().field("t5").value(t5).endObject());

    expected = "{'t5':'" + formatter.print(t5) + "'}";
    assertResult(expected, () -> builder().startObject().field("t5", t5, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("t5").value(t5, formatter).endObject());

    Instant i1 = new Instant(1451606400000L); // 2016-01-01T00:00:00.000Z
    expected = "{'i1':'2016-01-01T00:00:00.000Z'}";
    assertResult(expected, () -> builder().startObject().field("i1", i1).endObject());
    assertResult(expected, () -> builder().startObject().field("i1").value(i1).endObject());

    Instant i2 = new Instant(1482652782213L); // 2016-12-25T07:59:42.213Z
    expected = "{'i2':'" + formatter.print(i2) + "'}";
    assertResult(expected, () -> builder().startObject().field("i2", i2, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("i2").value(i2, formatter).endObject());

    expectNonNullFormatterException(() -> builder().startObject().field("t3", t3, null).endObject());
    expectNonNullFormatterException(() -> builder().startObject().field("t3").value(t3, null).endObject());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:54,代码来源:BaseXContentTestCase.java

示例13: calculateThresholdDate

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private String calculateThresholdDate(Period period, String datePattern){
    DateTime thresholdDate = new DateTime().minus(period);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(datePattern);
    return fmt.print(thresholdDate);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:6,代码来源:ArchiveService.java

示例14: parseFilters

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static Map<String, String> parseFilters(Long domainId, JSONObject jsonObject)
    throws ParseException {
  Map<String, String> filters = new HashMap<>();
  filters.put(TOKEN + QUERY_DOMAIN, String.valueOf(domainId));
  String periodicity;
  String dateFormat;
  switch (jsonObject.getString(PERIODICITY)) {
    case PERIODICITY_MONTH:
      periodicity = MONTH;
      dateFormat = DATE_FORMAT_MONTH;
      break;
    case PERIODICITY_WEEK:
      periodicity = WEEK;
      dateFormat = DATE_FORMAT_DAILY;
      break;
    default:
      periodicity = DAY;
      dateFormat = DATE_FORMAT_DAILY;
  }
  filters.put(TOKEN_PERIODICITY, periodicity);
  DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(Constants.DATE_FORMAT_CSV);
  DateTimeFormatter mDateTimeFormatter = DateTimeFormat.forPattern(dateFormat);
  String from;
  String to;
  if (jsonObject.has(LEVEL) && LEVEL_DAY.equals(jsonObject.getString(LEVEL))) {
    DateTime toDateTime = dateTimeFormatter.parseDateTime(jsonObject.getString(FROM));
    if(PERIODICITY_WEEK.equals(jsonObject.getString(LEVEL_PERIODICITY))) {
      toDateTime = toDateTime.plusWeeks(1).minusDays(1);
    } else {
      toDateTime = toDateTime.plusMonths(1).minusDays(1);
    }
    to = dateTimeFormatter.print(toDateTime);
    from = dateTimeFormatter.print(dateTimeFormatter.parseDateTime(jsonObject.getString(FROM)));
  } else {
    from = mDateTimeFormatter.print(dateTimeFormatter.parseDateTime(jsonObject.getString(FROM)));
    to = mDateTimeFormatter.print(dateTimeFormatter.parseDateTime(jsonObject.getString(TO)));
  }
  filters.put(TOKEN_START_TIME, from);
  filters.put(TOKEN_END_TIME, to);
  for (String filter : OPTIONAL_FILTER_MAP.keySet()) {
    if (jsonObject.has(filter)) {
      switch (filter) {
        case MTYPE:
          if (jsonObject.has(filter) && StringUtils.isNotEmpty(jsonObject.getString(filter))) {
            filters.put(TOKEN + OPTIONAL_FILTER_MAP.get(filter),
                    CharacterConstants.SINGLE_QUOTES+jsonObject.getString(filter)+CharacterConstants.SINGLE_QUOTES);
          }
          break;
        default:
          String value = String.valueOf(jsonObject.get(filter));
          if (NUMERIC_FIELDS.contains(filter)) {
            filters.put(TOKEN + OPTIONAL_FILTER_MAP.get(filter), value);
          } else {
            filters.put(TOKEN + OPTIONAL_FILTER_MAP.get(filter), encloseFilter(value));
          }
          break;
      }
    }
  }
  if(filters.containsKey(TOKEN+QUERY_ATYPE) && filters.containsKey(TOKEN+QUERY_MTYPE)){
    filters.remove(TOKEN+QUERY_MTYPE);
  }
  return filters;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:65,代码来源:QueryHelper.java

示例15: onBindViewHolder

import org.joda.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(TrainViewHolder holder, int position) {

    final Suggestion<TrainSuggestion> t = suggestedTrains.get(position);
    String title = t.getData().getName();
    if (t.getData().getDepartureDate() != null) {
        DateTimeFormatter df = DateTimeFormat.forPattern("HH:mm");
        title += " - " + df.print(t.getData().getDepartureDate());
    }
    if (t.getData().getOrigin() != null) {
        title += " - " + t.getData().getOrigin().getLocalizedName();
    }
    if (t.getData().getDirection() != null) {
        title += " - " + t.getData().getDirection().getLocalizedName();
    }
    holder.vStation.setText(title);

    switch (t.getType()) {
        case FAVORITE:
            holder.vIcon.setVisibility(View.VISIBLE);
            holder.vIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_star));
            break;
        case HISTORY:
            holder.vIcon.setVisibility(View.VISIBLE);
            holder.vIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_history));
            break;
        default:
            // No default icon
            break;
    }

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onRecyclerItemClick(TrainSuggestionsCardAdapter.this, t);
            }
        }
    });

    holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            if (longClickListener != null) {
                longClickListener.onRecyclerItemLongClick(TrainSuggestionsCardAdapter.this, t);
            }
            return false;
        }
    });
}
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:51,代码来源:TrainSuggestionsCardAdapter.java


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