Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:47:03+00:00 2026-06-15T15:47:03+00:00

How do I format a javax.time.Instant as a string in the local time zone?

  • 0

How do I format a javax.time.Instant as a string in the local time zone? The following translates a local Instant to UTC, not to the local time zone as I was expecting. Removing the call to toLocalDateTime() does the same. How can I get the local time instead?

public String getDateTimeString( final Instant instant )
{
    checkNotNull( instant );
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendPattern( "yyyyMMddHHmmss" ).toFormatter();
    return formatter.print( ZonedDateTime.ofInstant( instant, TimeZone.UTC ).toLocalDateTime() );
}

Note: We’re using the older version 0.6.3 of the JSR-310 reference implementation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:47:05+00:00Added an answer on June 15, 2026 at 3:47 pm

    The question was about version 0.6.3 of the JSR-310 reference implementation, long before the arrival of Java 8 and the new date library


    I gave up on JSR-310 classes DateTimeFormatter and ZonedDateTime and instead resorted to old fashioned java.util.Date and java.text.SimpleDateFormat:

    public String getDateTimeString( final Instant instant )
    {
        checkNotNull( instant );
        DateFormat format = new SimpleDateFormat( "yyyyMMddHHmmss" );
        Date date = new Date( instant.toEpochMillisLong() );
        return format.format( date );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to format a UTC time into any arbitrary string format
I'm parsing timestamps. They are forced to my local time zone (Europe/London) when I
Using Java String.format() how do I format a string to result in Time -
I wrote this following java code to format the date and time in specific
I have a .dll library which exports a function in the following format: _Java_folder1_folder2_folder3_JavaClassName_javamethodname@16
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Customer_
import java.util.*; import java.io.*; public String recToString (boolean format) { Date date = new
The following time formats are in outlook calendar file DTSTART;TZID=Eastern:20100728T140000 DTEND;TZID=Eastern:20100728T150000 how to convert
I am using android.text.format.DateFormat.format(yyyy-MM-dd hh:mm:ss, new java.util.Date()) to get time & date. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.