0

I've created the function below:

public static String marshalDate(Calendar value) {
    if (value == null) {
        return null;
    } else {
        DateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        String format = date.format(value.getTime());
        return format;
    }
}

The input will be Calendar, the string value is: 2014-10-17 00:00:00.000000

The expected result after running the function above should be:

2014-10-17

it works properly when I deploy the spring boot application locally and hitting the API on local.

But when deploying the spring boot application on AWS, and I was hitting the API from local, the value that I received is: 2014-10-17-04:00

I guess the server was returning the timezone as the suffix.

How can I remove the -04:00 with function above?

Thank you very much

Hung Bang Quan
  • 151
  • 2
  • 9
  • The problem is not in the code that you have shown us. I can’t guess where it is then. – Ole V.V. Feb 04 '21 at 17:50
  • 1
    I recommend you don’t use `Calendar`. That class is poorly designed and long outdated. Instead use `LocalDate` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). Extra plus: its `toString` method gives you the string that you want. – Ole V.V. Feb 04 '21 at 18:53
  • @OleV.V. yes, you're right. But the Calendar is generated by jaxb, so I could not decide which will be used. – Hung Bang Quan Feb 05 '21 at 01:37
  • 1
    I just saw a new thing, thought it can be the root cause of this problem. There are 2 classes same name and package inside jar. they come from 2 different dependencies. The spring boot has picked the first one that is found to use. someway somehow it picked the class that not containing the method above. – Hung Bang Quan Feb 05 '21 at 01:41
  • An interesting observation and a likely cause for the behaviour that you have observed, – Ole V.V. Feb 05 '21 at 03:57

1 Answers1

0

I want to confirm that the implementation above is correct. The reason for my problem comes from another aspect. Jaxb has generated 2 classes same name and package inside Jar, and the context will pick the first one that is found to use. As always it was not picking my implementation.

Hung Bang Quan
  • 151
  • 2
  • 9