The conversion you need requires the offset from UTC/Greewich, or a time-zone.
If you have an offset, there is a dedicated method on LocalDateTime
for this task:
long epochSec = localDateTime.toEpochSecond(zoneOffset);
If you only have a ZoneId
then you can obtain the ZoneOffset
from the ZoneId
:
ZoneOffset zoneOffset = ZoneId.of("Europe/Oslo").getRules().getOffset(ldt);
But you may find conversion via ZonedDateTime
simpler:
long epochSec = ldt.atZone(zoneId).toEpochSecond();