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


Java DateTimeFormatter.format方法代码示例

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


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

示例1: main

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
     * Main method.
     * @param args  no arguments needed
     */
    public static void main(String[] args) {
        Clock clock = Clock.systemDefaultZone();

        ZonedDateTime zdt = ZonedDateTime.now(clock);
        System.out.println("Current date-time: " + zdt);

        ZonedDateTime zdtNewYork = ZonedDateTime.now(Clock.system(ZoneId.of("America/New_York")));
        System.out.println("Current date-time in New York: " + zdtNewYork);

        ZonedDateTime zdtParis = ZonedDateTime.now(Clock.system(ZoneId.of("Europe/Paris")));
        System.out.println("Current date-time in Paris: " + zdtParis);

        LocalDateTime ldt = LocalDateTime.now(clock);
        System.out.println("Current local date-time: " + ldt);

        Year year = Year.now(clock);
        System.out.println("Year: " + year.getValue());

        LocalDate today = LocalDate.now(clock);
        System.out.println("Today: " + today);

        System.out.println("Current day-of-year: " + today.get(DAY_OF_YEAR));

        LocalTime time = LocalTime.now(clock);
        System.out.println("Current time of day: " + time);

        LocalDate later = LocalDate.now(clock).plusMonths(2).plusDays(3);
        System.out.println("Two months three days after today: " + later);

//        ISOPeriod period = ISOPeriod.of(3, MONTHS);
//        LocalDate moreLater = LocalDate.now(clock).plus(period);
//        System.out.println("Period " + period + " after today : " + moreLater);

        LocalDate dec = LocalDate.now(clock).with(DECEMBER);
        System.out.println("Change to same day in December: " + dec);

        LocalDate lastDayOfMonth = LocalDate.now(clock).with(lastDayOfMonth());
        System.out.println("Last day of month: " + lastDayOfMonth);

///        LocalDate tempDate = LocalDate.now(clock);
//        DateTimeFields fri13matcher = DateTimeFields.of(
//                DAY_OF_WEEK, FRIDAY.getValue(), DAY_OF_MONTH, 13);
//        boolean fri13 = fri13matcher.matches(tempDate);
//        System.out.println("Is Friday the Thirteenth: " + fri13);

        LocalDateTime dt = LocalDateTime.of(2008, 3, 30, 1, 30);
        System.out.println("Local date-time in Spring DST gap: " + dt);

        ZonedDateTime resolved = ZonedDateTime.of(dt, ZoneId.of("Europe/London"));
        System.out.println("...resolved to valid date-time in Europe/London: " + resolved);

        String formattedRFC = DateTimeFormatter.RFC_1123_DATE_TIME.format(resolved);
        System.out.println("...printed as RFC1123: " + formattedRFC);

        DateTimeFormatter f = new DateTimeFormatterBuilder()
            .appendValue(YEAR, 4, 10, SignStyle.ALWAYS)
            .appendLiteral(' ')
            .appendText(MONTH_OF_YEAR)
            .appendLiteral('(')
            .appendValue(MONTH_OF_YEAR)
            .appendLiteral(')')
            .appendLiteral(' ')
            .appendValue(DAY_OF_MONTH, 2)
            .toFormatter(Locale.ENGLISH);
        String formatted = f.format(resolved);
        System.out.println("...printed using complex format: " + formatted);

        MonthDay bday = MonthDay.of(DECEMBER, 3);
        System.out.println("Brazillian birthday (no year): " + bday);
    }
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:75,代码来源:Examples.java

示例2: dateToString

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Converts a {@link TemporalAccessor} object to a string representation.
 *
 * @param temporalAccessor {@link TemporalAccessor} object.
 * @param df               Date format.
 * @return Date string formatted on the right way.
 */
@NonNull
public static String dateToString(@NonNull TemporalAccessor temporalAccessor, @NonNull DateTimeFormatter df) {
  return df.format(temporalAccessor);
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:12,代码来源:DateHelper.java

示例3: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Formats the given datetime object according to the provided pattern.
 *
 * @see <a href="http://download.java.net/jdk8/docs/api/java/time/format/DateTimeFormatter.html#patterns">Supported Patterns</a>
 *
 * @param datetime datetime object
 * @param pattern Supported pattern
 * @return The formatted {@code TemporalAccessor}
 */
@Export
public String format(TemporalAccessor datetime, String pattern) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
    return formatter.format(datetime);
}
 
开发者ID:yahoo,项目名称:yql-plus,代码行数:15,代码来源:DateTime.java

示例4: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Outputs this time as a {@code String} using the formatter.
 * <p>
 * This time will be passed to the formatter
 * {@link DateTimeFormatter#format(TemporalAccessor) print method}.
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted time string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:15,代码来源:OffsetTime.java

示例5: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Outputs this year-month as a {@code String} using the formatter.
 * <p>
 * This year-month will be passed to the formatter
 * {@link DateTimeFormatter#format(TemporalAccessor) print method}.
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted year-month string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:15,代码来源:YearMonth.java

示例6: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Outputs this month-day as a {@code String} using the formatter.
 * <p>
 * This month-day will be passed to the formatter
 * {@link DateTimeFormatter#format(TemporalAccessor) print method}.
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted month-day string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:15,代码来源:MonthDay.java

示例7: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Outputs this date-time as a {@code String} using the formatter.
 * <p>
 * This date-time will be passed to the formatter
 * {@link DateTimeFormatter#format(TemporalAccessor) print method}.
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted date-time string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:15,代码来源:OffsetDateTime.java

示例8: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Outputs this date-time as a {@code String} using the formatter.
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted date-time string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:12,代码来源:ChronoZonedDateTime.java

示例9: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Formats this date using the specified formatter.
 * <p>
 * This date will be passed to the formatter to produce a string.
 * <p>
 * The default implementation must behave as follows:
 * <pre>
 *  return formatter.format(this);
 * </pre>
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted date string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:19,代码来源:ChronoLocalDate.java

示例10: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Formats this date-time using the specified formatter.
 * <p>
 * This date-time will be passed to the formatter to produce a string.
 * <p>
 * The default implementation must behave as follows:
 * <pre>
 *  return formatter.format(this);
 * </pre>
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted date-time string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:19,代码来源:ChronoLocalDateTime.java

示例11: format

import org.threeten.bp.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Outputs this year as a {@code String} using the formatter.
 * <p>
 * This year will be passed to the formatter
 * {@link DateTimeFormatter#format(TemporalAccessor) print method}.
 *
 * @param formatter  the formatter to use, not null
 * @return the formatted year string, not null
 * @throws DateTimeException if an error occurs during printing
 */
public String format(DateTimeFormatter formatter) {
    Jdk8Methods.requireNonNull(formatter, "formatter");
    return formatter.format(this);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:15,代码来源:Year.java


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