René's URL Explorer Experiment


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/

direct link

Domain: thecodeforge.io


Hey, it has json ld scripts:
{
  "@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:typewebsite
og:imagehttps://thecodeforge.io/assets/og-image.png
og:image:width1200
og:image:height630

Links:

TheCodeForge https://thecodeforge.io/
Javahttps://thecodeforge.io/java/
Buy me a coffee https://ko-fi.com/thecodeforge
1Lambda Expressions in Javahttps://thecodeforge.io/java/lambda-expressions-java/
2Stream API in Javahttps://thecodeforge.io/java/stream-api-java/
3Optional Class in Javahttps://thecodeforge.io/java/optional-class-java/
4Functional Interfaces in Javahttps://thecodeforge.io/java/functional-interfaces-java/
5Method References in Javahttps://thecodeforge.io/java/method-references-java/
6Default Methods in Interfacehttps://thecodeforge.io/java/default-methods-interface-java/
7Date and Time API in Java 8https://thecodeforge.io/java/date-time-api-java8/
8forEach and Map Operations in Streamhttps://thecodeforge.io/java/foreach-map-stream-java/
9Collectors in Java Stream APIhttps://thecodeforge.io/java/collectors-stream-api-java/
10var Keyword in Java 10https://thecodeforge.io/java/var-keyword-java10/
11Records in Java 16https://thecodeforge.io/java/records-java16/
12Sealed Classes in Java 17https://thecodeforge.io/java/sealed-classes-java17/
13Pattern Matching in Javahttps://thecodeforge.io/java/pattern-matching-java/
14CompletableFuture vs Futurehttps://thecodeforge.io/java/completablefuture-vs-future-java/
15Text Blocks in Java 15https://thecodeforge.io/java/text-blocks-java15/
16Java 25 New Features — What Changed and Why Minecraft Upgradedhttps://thecodeforge.io/java/java-25-new-features/
← Back to Java track https://thecodeforge.io/java/
Homehttps://thecodeforge.io/
Javahttps://thecodeforge.io/java/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
 ● Production Incidenthttps://thecodeforge.io/java/date-time-api-java8/#v2-production-incident
 🔎 Debug Guidehttps://thecodeforge.io/java/date-time-api-java8/#v2-debug-guide
 ⚙ Triage Commandshttps://thecodeforge.io/java/date-time-api-java8/#v2-triage-commands
Java 8https://thecodeforge.io/interview/java8-interview-questions/
machinehttps://thecodeforge.io/ml-ai/introduction-machine-learning/
designhttps://thecodeforge.io/java/design-patterns-java/
factoryhttps://thecodeforge.io/java/factory-pattern-java/
workinghttps://thecodeforge.io/java/json-java/
→PHP Timezone Handling — Double-Booked Slots from Blind SpotLondon and Paris 10:00 AM slots merged — a timezone blind spot. Debug date/time issues: 1970-01-01, offset bugs. Root cahttps://thecodeforge.io/php/php-date-time/
→Python datetime — utcnow() DST Bug That Shifts Datesdatetime.utcnow() returns naive timestamps that shift dates during DST transitions. A one-hour offset crossed date boundhttps://thecodeforge.io/python/datetime-module-python/
→SQL Date Range Bug - BETWEEN Missed 1,847 OrdersThe BETWEEN TIMESTAMP bug cost 1,847 monthly orders - here's the exact alternative, index-friendly pattern with >= and <https://thecodeforge.io/database/sql-date-time-functions/
→Java Synchronization — a costly volatile lost updateProduction volatile counter lost 0.5% trades — read-increment-write not atomic. AtomicLong or CAS fixes it. See JVM monihttps://thecodeforge.io/java/synchronization-java/
→Java Multithreading: volatile Counter Lost IncrementsA volatile int counter lost increments every 1000 requests under load. Root cause: non-atomic count++. Fix with AtomicInhttps://thecodeforge.io/java/multithreading-java/
Bisection Method — Numerical Root FindingBeginnerhttps://thecodeforge.io/dsa/bisection-method/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
←PreviousDefault Methods in Interfacehttps://thecodeforge.io/java/default-methods-interface-java/
NextforEach and Map Operations in Stream→https://thecodeforge.io/java/foreach-map-stream-java/
LinkedIn https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
Facebook https://www.facebook.com/profile.php?id=61583020033815
YouTube https://www.youtube.com/channel/UCMar7CF2EmCF1I2tw1tNVuQ
Javahttps://thecodeforge.io/java/
Pythonhttps://thecodeforge.io/python/
C / C++https://thecodeforge.io/c-cpp/
JavaScripthttps://thecodeforge.io/javascript/
DSAhttps://thecodeforge.io/dsa/
Databasehttps://thecodeforge.io/database/
System Designhttps://thecodeforge.io/system-design/
DevOpshttps://thecodeforge.io/devops/
C# / .NEThttps://thecodeforge.io/csharp/
PHPhttps://thecodeforge.io/php/
ML / AIhttps://thecodeforge.io/ml-ai/
Interviewhttps://thecodeforge.io/interview/
CS Fundamentalshttps://thecodeforge.io/cs-fundamentals/
Rusthttps://thecodeforge.io/rust/
Toolshttps://thecodeforge.io/tools/
Cheatsheetshttps://thecodeforge.io/cheatsheets/
Mobilehttps://thecodeforge.io/mobile/
Data Analyticshttps://thecodeforge.io/data-analytics/
Securityhttps://thecodeforge.io/security/
Frontendhttps://thecodeforge.io/frontend/
Data Engineeringhttps://thecodeforge.io/data-engineering/
Testinghttps://thecodeforge.io/testing/
Cloudhttps://thecodeforge.io/cloud/
Observabilityhttps://thecodeforge.io/observability/
Web Platformhttps://thecodeforge.io/web-platform/
🧯 Errors Explainedhttps://thecodeforge.io/errors/
⚒ Blueprintshttps://thecodeforge.io/blueprints/
⌨ Practicehttps://thecodeforge.io/practice/
Interview Prephttps://thecodeforge.io/interview/
DSA Problemshttps://thecodeforge.io/dsa/
Developer Toolshttps://thecodeforge.io/tools/
Cheat Sheetshttps://thecodeforge.io/cheatsheets/
Abouthttps://thecodeforge.io/about/
Sitemaphttps://thecodeforge.io/sitemap.xml
Privacyhttps://thecodeforge.io/privacy.html

Viewport: width=device-width, initial-scale=1.0

Robots: max-image-preview:large


URLs of crawlers that visited me.