I have a set of data containing latitude, longitude value, time and some other my application oriented values. In my application, a device is doing a job in a particular location during some time. So, it records the location and time. I want to import this record to postgresql database by a small java code. I made the time column as "timestamp with time zone" such as

String sql2 = "CREATE TABLE "+table_name +
              " (MachineId VARCHAR(20), " +
              " Timing TIMESTAMP(8) with time zone, " +
              " WorkMode INTEGER, " +
              " Latitude DOUBLE PRECISION, " +
              " Longitude DOUBLE PRECISION)"; 

and inserted only the time values such as

SimpleDateFormat original = new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss:SSS");
java.sql.Timestamp ts = null; 
try {
    java.util.Date timing = original.parse(time);
    ts = new java.sql.Timestamp(timing.getTime());
} catch (ParseException e) {
String sql = "INSERT INTO "+table_name +
             " (MachineId, "+
             " timing, " +
             " workmode, " +
             " latitude, " +
             " longitude)" +
             " VALUES" + 
             " ("+i+","+
             " '"+ts+"', " +
               workmode+", " +
               lat+", " +

But in postgres, it is showing "time+02" so, UTC+02 time zone is automatically detected which is correct time zone for my data. How does postgres detect this? Does this detect from lat and long values? Or what else?

closed as off-topic by DPSSpatial, pLumo, whyzar, aldo_tapia, Dan C Feb 6 '18 at 15:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – DPSSpatial, pLumo, aldo_tapia, Dan C
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Other clients would set the timezone when connecting to the db. It has nothing to do with the coordinates you have entered. – JGH Feb 6 '18 at 14:30

Java will have a default TimeZone set which is applied to all Dates as they are created. So this line is the one that sets the timezone.

java.util.Date timing = original.parse(time);

You can override the one that is set in your JVM by using a line like:

  • Ok, but how java detected correct time zone? Is it from my computer's time zone? As both are in same time zone; my data and my computer. – LSG Feb 6 '18 at 14:46
  • 3
    Yes, the default will be read from your machine's settings – Ian Turton Feb 6 '18 at 14:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.