Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Utility to parse String to Date according to a target class, and the pattern strings. And format Date to String based on a pattern string.

License

NotificationsYou must be signed in to change notification settings

joutvhu/date-parser

Repository files navigation

GitHubcodecov

This is a Date Utility with two purposes:

  • Parse String to Date according to a target class, and the pattern strings.
  • Format Date to String based on a pattern string.

Installation

  • If you are using Gradle just add the following dependency to yourbuild.gradle.
implementation"com.github.joutvhu:date-parser:1.0.0"
  • Or add the following dependency to yourpom.xml if you are using Maven.
<dependency>    <groupId>com.github.joutvhu</groupId>    <artifactId>date-parser</artifactId>    <version>1.0.0</version></dependency>

Using

DateFormatter

  • withConvertor(Class<T> typeOfConvertor, Convertor<T> convertor) orwithConvertor(Convertor<T> convertor) used to add a custom convertor to theDateFormatter.

  • withLocale(Locale defaultLocale) used to set defaultjava.util.Locale, if this value is null the default value isLocale.getDefault().

  • withZone(TimeZone defaultZone) used to set defaultjava.util.TimeZone, if this value is null the default value isTimeZone.getDefault().

  • withWeekFields(WeekFields defaultWeekFields) used to set defaultjava.time.temporal.WeekFields, if this value is null the default value isWeekFields.of(locale).

  • withStrategyFactory(StrategyFactory strategyFactory) used to overrideStrategyFactory.

    • Use this method to add, update or delete aStrategy.
  • parse(Class<T> type, String value, String... patterns) used to parse string to date.

    • type is the type of target object you want to get.
    • value is the input string you want to convert to the target object.
    • patterns are the possible formats of the input string.
  • format(T object, String pattern) used to format an object to a target string.

    • object is the input object you want to convert to string.
    • pattern is the format of the target string.

DateParser

  • DateParser.formatter() will be return a newDateFormatter.

  • DateParser.parse(Class<T> type, String value, String... patterns) is equivalent toDateParser.formatter().parse(Class<T> type, String value, String... patterns).

  • DateParser.format(T object, String pattern) is equivalent toDateParser.formatter().format(T object, String pattern).

Example

  • Parse Date
Datedate =DateParser.formatter().parse(Date.class,"2021-06-27 21:52:25.408","yyyy-MM-dd HH:mm:ss.SSS");LocalDateTimelocalDateTime =DateParser.parse(LocalDateTime.class,"2021-06-27 21:52:25.408","yyyy-MM-dd HH:mm:ss.SSS");Instantinstant =DateParser.parse(Instant.class,"2021-06-28T02:22:48.780101Z","yyyy-MM-dd'T'HH:mm:ss.SSSZ");DayOfWeekdayOfWeek =DateParser.formatter().withWeekFields(WeekFields.ISO).parse(DayOfWeek.class,"Sun","E");
  • Format Date
Stringdate =DateParser.format(newDate(),"MMM dd, yyyy hh:mm:ss a");Stringinstant =DateParser.format(Instant.now(),"yyyy-MM-dd'T'HH:mm:ss.SSSX");StringyearMonth =DateParser.format(YearMonth.of(2021,Month.DECEMBER),"Mo yyyy");

About

Utility to parse String to Date according to a target class, and the pattern strings. And format Date to String based on a pattern string.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Languages


[8]ページ先頭

©2009-2025 Movatter.jp