Time Formatter
The TimeFormatter
class is a useful tool class to format in different ways the "time"
// Get an instance of the TimeFormatter
TimeFormatter timeFormatter = TimeFormatter.getInstance();
// Change the values of the formatter
timeFormatter.changeFormatter("new_pattern", new_locale);
// or pass pattern as argument in all methods to change only in that formatting
String stringDate = timeFormatter.formatNowAsString("yyyy/MM/dd HH:mm:ss"); // --> 2024/04/14 13:46:30
// string format
String stringDate = timeFormatter.formatAsString(time_in_millis); // --> 2024/04/14 13:46:30
// long format
System.out.println(timeFormatter.formatAsTimestamp("string_date")); // --> 1670261677000
// date format
// with string as argument
System.out.println(timeFormatter.formatAsDate("string_date")); // --> Sun Apr 14 13:46:30 CET 2024
// with long as argument
System.out.println(timeFormatter.formatAsDate(time_in_millis); // --> Sun Apr 14 13:46:30 CET 2024
Content copied to clipboard
Author
N7ghtm4r3 - Tecknobit
Constructors
Link copied to clipboard
private constructor()
Constructor to init the TimeFormatter No-any params required
Constructor to init the TimeFormatter
Constructor to init the TimeFormatter
Constructor to init the TimeFormatter
Properties
Link copied to clipboard
DEFAULT_PATTERN
the default pattern used for the formatterLink copied to clipboard
formatter
the formatter used to format the valuesFunctions
Link copied to clipboard
This method is used to set a new pattern for the formatter instance
Link copied to clipboard
This method is used to set a new locale for the formatter instance
Link copied to clipboard
This method is used to set a new pattern for the formatter instance
Link copied to clipboard
This method is used to format a string-date as date
This method is used to format a timestamp value as date
Link copied to clipboard
This method is used to format the current timestamp as string
Link copied to clipboard
This method is used to format a timestamp as string
Link copied to clipboard
This method is used to format a string-date value as timestamp
This method is used to format a date value as timestamp
Link copied to clipboard
This method is used to format the current timestamp as a date No-any params required
This method is used to format the current timestamp as a date
Link copied to clipboard
This method is used to format the current timestamp as string No-any params required
Link copied to clipboard
This method is used to format the current instant as timestamp No-any params required
Link copied to clipboard
Method to get an instance of TimeFormatter No-any params required
Method to get an instance of TimeFormatter