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 8827849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:28:16+00:00 2026-06-14T07:28:16+00:00

I discovered that the dates being read through Ormlite don’t return correctly when changing

  • 0

I discovered that the dates being read through Ormlite don’t return correctly when changing my device’s time zone.

For instance, when switching from Amsterdam time to London time, the date should shift forward an hour. However, when reading the date from the database, it returns the same time, but now in the London time zone.

I’m storing my field as follows:

@DatabaseField(canBeNull = true)
private Date registration;
  • 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-14T07:28:17+00:00Added an answer on June 14, 2026 at 7:28 am

    Looking into the database, I discovered that Ormlite by default stores Date objects in the format YYYY-MM-DD HH:MM:SS.SSS. As there is no information about the time zone, it assumes the device’s current time zone.

    Easy way: timestamp

    The trick is to store it in a UTC timestamp instead:

    @DatabaseField(canBeNull = true, dataType = DataType.DATE_LONG)
    private Date registration;
    

    Advanced way: persister

    If you want to get your hands dirty writing your own persister, this is how it’s done:

    @DatabaseField(persisterClass = DateConverter.class)
    private Date registration;
    

    Where:

    public static class DateConverter extends LongType {
    
        private static final DateConverter singleton = new DateConverter();
    
        protected DateConverter() {
            super(SqlType.LONG, new Class<?>[] {
                    Date.class
            });
        }
    
        public static DateConverter getSingleton() {
            return singleton;
        }
    
        @Override
        public Object javaToSqlArg(FieldType fieldType, Object javaObject) 
                throws SQLException {
            if (javaObject instanceof Date) {
                return ((Date) javaObject).getTime();
            }
            return javaObject;
        }
    
        @Override
        public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos)
                throws SQLException {
            if (sqlArg instanceof Long) {
                return new Date((Long) sqlArg);
            }
            return null;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just discovered that TabPages don't resize with a TabControl until after they're selected.
I have an iPhone game that dispenses in-game currency over time, and someone discovered
I discovered that it is possible to extract the hard-coded strings from a binary.
I've discovered that my Phonegap/Cordova app on iOS is saving all the pictures I
I recently discovered that all Windows 7 machines have an handwriting recognition API within
I just discovered that truncate {table} statements are not caught by most database triggers.
We have discovered that one of our auto generated assemblies is throwing a StackOverflowException
I recently discovered that when you have a page set to session readonly and
I recently discovered that I can use lambdas to create simple event handlers. I
Since I discovered that HTTP headers are case-insensive according to the RFC, i was

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.