tl;dr
LocalDate.now( ZoneId.of( "America/Montreal" ) )
.with( TemporalAdjusters.previousOrSame( DayOfWeek.SUNDAY ) )
.atStartOfDay( ZoneId.of( "America/Montreal" ) )
.plus( Duration.ofMinutes( 720 ) )
Using java.time
The modern way is with the java.time classes.
Which week? I will assume you want the Sunday of the current week.
ZoneId z = ZoneId.of( "America/Montreal" ) ;
LocalDate today = LocalDate.now( z );
LocalDate sundayThisWeek = today.with( TemporalAdjusters.previousOrSame( DayOfWeek.SUNDAY ) );
Get the first moment of that date. Do not assume that means 00:00:00
as anomalies such as Daylight Saving Time (DST) may mean another time like 01:00:00
.
ZonedDateTime zdt = sundayThisWeek.atStartOfDay( z ); // First moment of the day.
You say you are given an input of a number of minutes. Represent that as a Duration
object.
Duration duration = Duration.ofMinutes( x );
Add the Duration
object to your ZonedDateTime
object.
720 (720 minutes into the week) so 12pm on Sunday
No, 720 minutes may result in some other time-of-day, such as 11 AM or 1 PM in the United States on the DST cutover day.
The objects do all the math for you, and handle anomalies such as Daylight Saving Time.
ZonedDateTime zdtLater = zdt.plus( duration );
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8 and SE 9 and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.