TL; DR
java.time.LocalDateTime.parse( "27/12/2010 11:29" , DateTimeFormatter.ofPattern( "dd/MM/uuuu HH:mm" ) ).plusMinutes( 30 )
2010-12-27T11: 59
Tip. If you intend to be a moment, a specific point on the timeline, apply the time zone context ( ZoneId
) to get the ZonedDateTime
.
java.time
Your Question uses the nasty old time classes with the earliest versions of Java, and your question uses the Joda-Time project, which is now in maintenance mode. Both were superseded by the java.time classes built into Java 8 and later.
Your string input is missing the time zone indicator or offset-from-UTC . So, java.time.LocalDateTime
as java.time.LocalDateTime
.
DateTimeFormatter f = DateTimeFormatter.ofPattern( "dd/MM/uuuu HH:mm" ) ; LocalDateTime ldt = LocalDateTime.parse( "27/12/2010 11:29" , f ) ;
ldt.toString (): 2010-12-27T11: 29
Please note that you do not have an actual moment, this is not a specific point on the timeline. This is only a vague idea of ββpotential moments in the range of about 26-27 hours. To determine the actual moment, put this in the context of the time zone (or offset): ZonedDateTime zdt = ldt.atZone( ZoneId.of( "Pacific/Auckland" ) ) ;
.
Add your minutes.
LocalDateTime later = ldt.plusMinutes( 30 ) ;
later.toString (): 2010-12-27T11: 59
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy datetime classes such as java.util.Date
, Calendar
and SimpleDateFormat
.
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
You can exchange java.time objects directly with your database. Use a JDBC driver that conforms to JDBC 4.2 or later. No strings needed, no java.sql.*
Classes needed.
Where to get java.time classes?
- Java SE 8 , Java SE 9 , and then
- Built in.
- Part of the standard Java API with integrated implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Most of the functionality of java.time has been ported to Java 6 and 7 in ThreeTen-Backport .
- Android
- Later versions of the Android package implementations of the java.time classes.
- For earlier Android (<26), the ThreeTenABP project adapts ThreeTen-Backport (mentioned above), see How to use ThreeTenABP ....
The ThreeTen-Extra project extends java.time with additional classes. This project is a proof of possible future additions to java.time. Here you can find useful classes such as Interval
, YearWeek
, YearQuarter
and more .