org.fujion.common.DateUtil类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.fujion.common.DateUtil类的一些代码示例,展示了DateUtil类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateUtil类的具体详情如下:
包路径:org.fujion.common.DateUtil
类名称:DateUtil

DateUtil介绍

[英]Utility methods for managing dates.
[中]管理日期的实用方法。

代码示例

代码示例来源:origin: org.fujion/fujion-common

/**
 * Converts a date/time value to a string, using the format dd-mmm-yyyy hh:mm. Because we cannot
 * determine the absence of a time from a time of 24:00, we must assume a time of 24:00 means
 * that no time is present and strip that from the return value.
 *
 * @param date Date value to convert.
 * @return Formatted string representation of the specified date, or an empty string if date is
 *         null.
 */
public static String formatDate(Date date) {
  return formatDate(date, false, false);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Sets the end date.
 *
 * @param endDate The end date.
 */
private void setEndDate(String endDate) {
  this.rawEndDate = endDate;
  this.endDate = DateUtil.parseDate(endDate);
}

代码示例来源:origin: org.hspconsortium.carewebframework/cwf-plugin-patientheader

private String formatDateAndAge(Date date) {
  return date == null ? null : DateUtil.formatDate(date) + " (" + DateUtil.formatAge(date) + ")";
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Returns a date with the current day (no time).
 *
 * @return Current date.
 */
public static Date today() {
  return stripTime(now());
}

代码示例来源:origin: org.hspconsortium.carewebframework/cwf-ui-reporting

/**
 * Returns the current date in standard format.
 *
 * @return Timestamp for current date.
 */
public String getTimestamp() {
  return DateUtil.formatDate(DateUtil.stripTime(new Date()));
}

代码示例来源:origin: org.fujion/fujion-common

private void testDate(Date date, boolean showTimezone, boolean ignoreTime) {
  String text = DateUtil.formatDate(date, showTimezone, ignoreTime);
  print(text);
  Date date2 = DateUtil.parseDate(text);
  String text2 = DateUtil.formatDate(date2, showTimezone, ignoreTime);
  assertEquals(text, text2);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Returns true if the date has an associated time.
 *
 * @param date Date value to check.
 * @return True if the date has a time component.
 */
public static boolean hasTime(Date date) {
  if (date == null) {
    return false;
  }
  
  long time1 = date.getTime();
  long time2 = stripTime(date).getTime();
  return time1 != time2; // Do not use "Date.equals" since date may be of type Timestamp.
}

代码示例来源:origin: org.fujion/fujion-common

@Test
public void testDateUtil() {
  testDate(now());
  testDate(today());
  testDate("T", today(), 0);
  testDate("N", now(), 100);
  testDate("T+30", DateUtil.addDays(today(), 30, false), 0);
  testDate("N+30", DateUtil.addDays(now(), 30, false), 100);
  testDate("T-4", DateUtil.addDays(today(), -4, false), 0);
  testDate("T-50s", new Date(today().getTime() - 50000), 0);
  testDate("N-50s", new Date(now().getTime() - 50000), 100);
  testDate("T-50h", new Date(today().getTime() - 50 * 60 * 60 * 1000), 0);
  testDate("T-50n", new Date(today().getTime() - 50 * 60 * 1000), 0);
  Date date = DateUtil.parseDate("19880302");
  testDate(date.toString(), date, 0);
}

代码示例来源:origin: org.fujion/fujion-common

@Test
public void testAge() {
  Date dob = DateUtil.toDate(27, 7, 1958);
  Date ref = DateUtil.toDate(1, 1, 2013);
  assertEquals("54 yrs", DateUtil.formatAge(dob, true, ref));
  assertEquals("54 yr", DateUtil.formatAge(dob, false, ref));
  dob = DateUtil.toDate(15, 12, 2012);
  assertEquals("17 days", DateUtil.formatAge(dob, true, ref));
  dob = DateUtil.toDate(30, 10, 2012);
  assertEquals("2 mos", DateUtil.formatAge(dob, true, ref));
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * <p>
 * Returns age as a formatted string expressed in days, months, or years, depending on whether
 * person is an infant (&lt; 2 mos), toddler (&gt; 2 mos, &lt; 2 yrs), or more than 2 years old.
 * </p>
 *
 * @param dob Date of person's birth
 * @return the age display string
 */
public static String formatAge(Date dob) {
  return formatAge(dob, true, null);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Formats a duration in ms.
 *
 * @param duration Duration in ms.
 * @return Formatted duration.
 */
public static String formatDuration(long duration) {
  return formatDuration(duration, null);
}

代码示例来源:origin: org.fujion/fujion-common

@Test
public void testElapsed() {
  assertEquals("0.1 seconds", DateUtil.formatElapsed(100.0, TimeUnit.SECONDS));
  assertEquals("1 second", DateUtil.formatElapsed(1000.0));
  assertEquals("1 minute", DateUtil.formatElapsed(60000.0));
  assertEquals("3.59 days", DateUtil.formatElapsed(309898934.0));
  assertEquals("98.2 years", DateUtil.formatElapsed(3098989343984.0));
  assertEquals("-98.2 years", DateUtil.formatElapsed(-3098989343984.0));
  
  assertEquals(100.0, DateUtil.parseElapsed("0.1 seconds"), 0.0);
  assertEquals(1000.0, DateUtil.parseElapsed("1 second"), 0.0);
  assertEquals(60000.0, DateUtil.parseElapsed("1 minute"), 0.0);
  assertEquals(310176000.0, DateUtil.parseElapsed("3.59 days"), 0.0);
  assertEquals(3098956320000.0, DateUtil.parseElapsed("98.2 years"), 0.0);
  assertEquals(-3098956320000.0, DateUtil.parseElapsed("-98.2 years"), 0.0);
  assertEquals(98.2, DateUtil.parseElapsed("98.2 years", TimeUnit.YEARS), 0.0);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Return elapsed time in ms to displayable format with units.
 *
 * @param elapsed Elapsed time in ms.
 * @param pluralize If true, pluralize units when appropriate.
 * @param abbreviated If true, use abbreviated form of units.
 * @param round If true, round result to an integer.
 * @return Elapsed time in displayable format.
 */
public static String formatElapsed(double elapsed, boolean pluralize, boolean abbreviated, boolean round) {
  return formatElapsed(elapsed, pluralize, abbreviated, round, null);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Strips the time component from a date.
 *
 * @param date Original date.
 * @return Date without the time component.
 */
public static Date stripTime(Date date) {
  return addDays(date, 0, true);
}

代码示例来源:origin: org.carewebframework/org.carewebframework.ui.core

/**
 * Update the datebox with the new value.
 *
 * @param date New date value.
 */
private void updateDatebox(Date date) {
  datebox.setValue(DateUtil.stripTime(date));
}

代码示例来源:origin: org.hspconsortium.carewebframework/cwf-ui-patientselection-core

addDemographic(root, "gender", patient.getGender());
addDemographic(root, "age", DateUtil.formatAge(patient.getBirthDate()));
addDemographic(root, "dob", patient.getBirthDate());
addDemographic(root, "dod", patient.getDeceased());

代码示例来源:origin: org.fujion/fujion-common

/**
 * Formats a duration in ms to the specified accuracy.
 *
 * @param duration Duration in ms.
 * @param accuracy Accuracy of output.
 * @return Formatted duration.
 */
public static String formatDuration(long duration, TimeUnit accuracy) {
  return formatDuration(duration, accuracy, true, false);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Return elapsed time in ms to displayable format with units.
 *
 * @param elapsed Elapsed time in ms.
 * @return Elapsed time in displayable format.
 */
public static String formatElapsed(double elapsed) {
  return formatElapsed(elapsed, true, false, false);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Converts a date/time value to a string, using the format dd-mmm-yyyy hh:mm. Because we cannot
 * determine the absence of a time from a time of 24:00, we must assume a time of 24:00 means
 * that no time is present and strip that from the return value.
 *
 * @param date Date value to convert.
 * @param showTimezone If true, time zone information is also appended.
 * @return Formatted string representation of the specified date, or an empty string if date is
 *         null.
 */
public static String formatDate(Date date, boolean showTimezone) {
  return formatDate(date, showTimezone, false);
}

代码示例来源:origin: org.hspconsortium.carewebframework/cwf-ui-reporting

/**
 * Retrieves a formatted header for the current patient.
 *
 * @return Formatted header.
 */
public String getPatientInfo() {
  Patient patient = PatientContext.getActivePatient();
  String text;
  if (patient == null) {
    text = "No Patient Selected";
  } else {
    Identifier mrn = FhirUtil.getMRN(patient); // May be null!
    text = FhirUtil.formatName(patient.getName());
    if (mrn != null) {
      text += "  #" + mrn.getValue();
    }
    String gender = patient.hasGender() ? patient.getGender().getDisplay() : "";
    if (!StringUtils.isEmpty(gender)) {
      text += "   (" + gender + ")";
    }
    Date deceased = patient.getDeceased() instanceof DateType ? ((DateType) patient.getDeceased()).getValue() : null;
    String age = DateUtil.formatAge(patient.getBirthDate(), true, deceased);
    text += "  Age: " + age;
    if (deceased != null) {
      text += "  Died: " + DateUtil.formatDate(deceased);
    }
  }
  return text;
}

相关文章