Incorrect time zone used in Java web service

I have a JAX-B java web service that I use to update a database. Each row in the updated table is represented by an object similar to the following: -

public class Item {
    private String id;
    private Date startDate;
    private Date endDate;

    public Item() { }

    ...

}

This class is created in a separate program and then passed through SOAP in a message similar to the one below: -

...

<item>
    <id>D001IAAC030</id>
    <startDate>2009-09-17T00:00:00.000+01:00</startDate>
    <endDate>2009-10-01T00:00:00.000+01:00</endDate>
</item>

...

As you can see, due to BST, the UTC time has an offset of +01: 00. However, when the object is sorted on the server (which is also located on my local machine), it returns to GMT and subtracts 1 hour from the date.

Can you tell me how I can: -

  • Set my Glassfish server to the correct locale so that dates are recognized by BST.
  • Tell me how I can intercept marshalling at the end of the web service so that I can set the time zone myself before the date is set.

TIA

Urf

+3
4

, Date () / UTC/GMT. , , Date.toString() JVM ( Calendar). ( JDK.)

, ,

Date now = new Date();
System.out.println(now.toString());
System.out.println(now.getTime())

Fri Oct 02 06:56:24 EST 2009
1254430584531

- GMT ​​/UTC.

/ Date . :

Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:MM:ss zzz yyyy");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(now.toString());
System.out.println(sdf.format(now));

Fri Oct 02 06:56:24 EST 2009
Thu Oct 01 20:56:24 UTC 2009

: Date , . ( - toString(), , .) , , ( ..), / DateFormat .

Javadoc Date:

' JDK 1.1 Date . , , , , ​​ . . , API . JDK 1.1, Calendar , DateFormat . .

Date, Calendars Formatters Javadoc, .

Glassfish . / , , . , , UTC ( db Date ), , / . , , DateFormat , +01: 00 ( , , , ).

, - , .

+5

, UTC Glassfish:

C:\glassfish4\GlassFish\BIN)

asadmin create-jvm-options -Duser.timezone=UTC
asadmin restart-domain
+3

c: \ glassfish3 \ bin \> asadmin list-jvm-options

,

<jvm-options>-Duser.timezone=UTC</jvm-options>

domain.xml jvm-

<jvm-options>-Duser.timezone = Brazil / East </ jvm-options> substituting the Brazil / East timezone by country

+1

Locale

Locale . a Locale : (a) , , .., (b) , , ( / ..).

JVM , . JVM .

java.time

. , Java, , . . java.time, Java 8 . , java.util.Date. . Oracle. Java 6 7 ThreeTen-Backport Android ThreeTenABP.

ISO 8601

ISO 8601. , , java.time / , .

String input = "2009-09-17T00:00:00.000+01:00";
OffsetDateTime odt = OffsetDateTime.parse( input );

, UTC, Instant. UTC - .

Instant instant = odt.toInstant();

ISO 8601, toString.

String output = instant.toString();  // 2009-09-16T23:00:00Z

, , ZoneId, ZonedDateTime. - UTC , (DST).

ZoneId zoneId = ZoneId.of( "Europe/London" );
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId );

, UTC:

Instant instant = Instant.now();

JAXB

Java Architecture for XML Binding (JAXB) java.time .

, ​​ , java.time, , , JAXB java.time?. , Joda-Time.

LocalDate

00:00:00 , . , , . , LocalDate.

0

Source: https://habr.com/ru/post/1719029/


All Articles