java.time
The java.time framework is built into Java 8 and later. These classes supplant the old troublesome classes such as java.util.Date/.Calendar. And these classes supplant the highly successful Joda-Time library.
Get the current moment on the timeline in UTC.
Instant instant = Instant.now();
Apply a time zone.
ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId );
Add 5 seconds. The "plus…" methods handle issues such as leap year, Daylight Saving Time, and other anomalies.
ZonedDateTime zdtLater = zdt.plusSeconds( 5 );
Use your language and country codes to determine a Locale
object.
Locale locale = new Locale( "fr" , "CA" ); // French, Canada (Québec)
Generate string. Let the formatter automatically localize per the Locale, translating to a human language like French and using cultural formatting norms (order of elements, comma versus period, etc.) such as in Québec Canada.
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL );
formatter = formatter.withLocale( locale );
String string = zdtLater.format( formatter );
Going the other direction. But try to avoid this direction. Localized strings of a date-time should be for display to the user, not for data-exchange.
ZonedDateTime zdtNew = ZonedDateTime.parse( string , formatter );