tl;dr
Use java.time.
(In Java syntax rather than Kotlin.)
LocalDate // Represent a date-only value.
.now( ZoneId.of( "Asia/Seoul" ) ) // Get the current date as seen in a particular time zone.
.with(
TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY )
) // Returns another LocalDate.
.atStartOfDay( ZoneId.of( "Asia/Seoul" ) ) // Determine the first moment of the day on that date in that time zone.
.toInstant() // Convert to UTC. Same moment, same point on the timeline.
.toEpochMilli() // Extract a count of milliseconds since 1970-01-01T00:00Z.
Avoid legacy classes
The legacy date-time classes are terrible, deeply flawed in their design. They were supplanted years ago by the modern java.time classes built into Java 8 and later.
An implementation is built into Android 26+. For earlier Android, the latest tooling makes most of the java.time functionality available via API desugaring.
java.time
LocalDate
need to get this week startdate like 2023-02-20
Use the LocalDate
class to represent a date only without a time-of-day and without an offset or time zone.
Using Java syntax (I've not yet learned Kotlin):
LocalDate today = LocalDate.now() ;
Generally best to be explicit about the time zone used to determine the current date.
ZoneId zoneId = ZoneId.of( "Asia/Seoul" ) ; // Or ZoneId.systemDefault().
LocalDate today = LocalDate.now() ;
TemporalAdjuster
Use a TemporalAdjuster
to move to another day of week. Note the DayOfWeek
enum, defining an object for each day of week.
LocalDate previousOrSameMonday = today.with( TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY ) ) ;
To get the following Sunday, add 6 days.
LocalDate sameOrNextSunday = previousOrSameMonday.plusDays( 6 ) ;
But… A span of time is usually better defined using the Half-Open approach. In Half-Open, the beginning is inclusive while the ending is exclusive. So a week starts on a Monday, running up to, but not including, the following Monday.
LocalDate startNextWeek = previousOrSameMonday.plusWeeks( 1 ) ;
Count from epoch
Apparently you want a count of milliseconds from an epoch reference date. I will assume your epoch reference is the first moment of 1970 as seen in UTC, 1970-01-01T00:00Z.
ZonedDateTime
To do this, we need to get the first moment of the day on that date as seen in a particular time zone.
Do not assume the day starts at 00:00. Some days on some dates in some zones start at another time-of-day such as 01:00. Let java.time determine the first moment of the day.
ZonedDateTime zdtStart = previousOrSameMonday.atStartOfDay( zoneId ) ;
Instant
Extract an Instant
, the same moment but as seen with an offset from UTC of zero hours-minutes-seconds.
Instant instant = zdtStart.toInstant() ;
From the Instant
extract a count from epoch.
long start = instant.toEpochMilli() ;
long end = startNextWeek.atStartOfDay( zoneId ).toInstant().toEpochMilli() ;
Compare
See if a moment lies within that week.
long now = Instant.now().toMilli() ;
if (
( ! now < start )
&&
( now < end )
) { … }