Title: Date and Time API in Java 8: LocalDateTime Zone Drift
Open Graph Title: Date and Time API in Java 8: LocalDateTime Zone Drift
Description: Server migration changed JVM timezone, shifting LocalDateTime by 6 hours. Why Instant or ZonedDateTime prevents midnight transaction failures.
Open Graph Description: Server migration changed JVM timezone, shifting LocalDateTime by 6 hours. Why Instant or ZonedDateTime prevents midnight transaction failures.
Opengraph URL: https://thecodeforge.io/java/date-time-api-java8/
Domain: thecodeforge.io
{
"@context": "https://schema.org",
"@type": "TechArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://thecodeforge.io/java/date-time-api-java8/"
},
"headline": "LocalDateTime Zone Drift — Why Timestamps Shifted 6 Hours",
"description": "Server migration changed JVM timezone, shifting LocalDateTime by 6 hours. Why Instant or ZonedDateTime prevents midnight transaction failures.",
"keywords": "LocalDateTime Zone Drift — Why Timestamps Shifted 6 Hours, Java, Intermediate, Java 8+ Features, Server migration changed JVM timezone, shifting LocalDateTime by 6 hours. Why Instant or ZonedDateTime prevents midnight transaction failures.",
"proficiencyLevel": "Intermediate",
"author": {
"@type": "Person",
"@id": "https://thecodeforge.io/about/#naren",
"name": "Naren",
"url": "https://thecodeforge.io/about/"
},
"publisher": {
"@type": "Organization",
"@id": "https://thecodeforge.io/#org",
"name": "TheCodeForge",
"url": "https://thecodeforge.io",
"logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
},
"datePublished": "2026-03-05T00:00:00+00:00",
"dateModified": "2026-10-31T00:00:00+00:00",
"url": "https://thecodeforge.io/java/date-time-api-java8/",
"inLanguage": "en",
"educationalLevel": "Intermediate",
"image": "https://thecodeforge.io/assets/og-image.png",
"isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
{"@type": "ListItem", "position": 2, "name": "Java", "item": "https://thecodeforge.io/java/"},
{"@type": "ListItem", "position": 3, "name": "LocalDateTime Zone Drift — Why Timestamps Shifted 6 Hours", "item": "https://thecodeforge.io/java/date-time-api-java8/"}
]
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is the difference between LocalDate and Date in Java 8?",
"acceptedAnswer": {
"@type": "Answer",
"text": "`LocalDate` is immutable, has no time component, and uses sensible month indexing (January = 1). `java.util.Date` is mutable, has time (to millisecond precision), and months are zero-indexed (January = 0). LocalDate is always preferred for date-only values."
}
},
{
"@type": "Question",
"name": "How do I convert between LocalDateTime and ZonedDateTime?",
"acceptedAnswer": {
"@type": "Answer",
"text": "LocalDateTime does not have a zone, so you must provide one: `ZonedDateTime zdt = localDateTime.atZone(ZoneId.of(\"UTC\"));`. To go back: `LocalDateTime ldt = zdt.toLocalDateTime();` but beware — this loses the time zone. Only do this if you are sure the result will be interpreted in the correct zone later."
}
},
{
"@type": "Question",
"name": "Why does plusDays(1) on a ZonedDateTime sometimes shift the time by an hour?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Because plusDays preserves the local time, not the offset. If you start at 10:00 AM on a day with offset -5, and the next day has offset -4 (after DST start), the ZonedDateTime will be 10:00 AM with the new offset, which corresponds to 9:00 AM UTC — a physical time shift of one hour. To avoid this, convert to Instant, add 24 hours, then convert back."
}
},
{
"@type": "Question",
"name": "Is DateTimeFormatter thread-safe?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes, DateTimeFormatter is immutable and thread-safe. Unlike SimpleDateFormat, you can share a single instance across threads without synchronization. Always create it as a static final field."
}
},
{
"@type": "Question",
"name": "How do I handle time zones in a microservices architecture?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Pass all timestamps between services as ISO-8601 strings in UTC (e.g., 2026-05-22T14:30:00Z). Use Instant or OffsetDateTime for serialization. Each service must never rely on its local time zone — set the JVM to UTC via -Duser.timezone=UTC. Convert to user local time only in the frontend or at the edge API layer."
}
}
]
}
| og:type | website |
| og:image | https://thecodeforge.io/assets/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: max-image-preview:large