Try this:
public static String cambiaNumeroFecha(Long fecha) {
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("yyyy-MM-dd");
Date d = new Date(fecha);
return dateFormat.format(d);
}
Javier
On Mon, 21 Jun 2021 at 05:40, [email protected] <[email protected]> wrote:
> Sorry, correction:
>
> public static String cambiaNumeroFecha(Long fecha) {
> Calendar c = Calendar.getInstance();
> Date d = new Date(fecha);
> c.setTime(d);
>
> String r = Integer.toString(c.get(Calendar.YEAR)) + "-"
> + Integer.toString(c.get(Calendar.MONTH)) + "-"
> + Integer.toString(c.get(Calendar.DAY_OF_MONTH));
> return r;
> }
>
> El Sunday, June 20, 2021 a la(s) 11:36:23 PM UTC-5, [email protected]
> escribió:
>
>> My app sends the date in milliseconds to a WS. Upon receiving it, I
>> convert it to date format in the WS, but it appears to me with differences
>> with respect to the initial value.
>> I decided to send the date in string format and as my logic in the app
>> always uses the date in milliseconds, it seemed correct to create a method
>> to return the date in string.
>>
>> The problem I have is that he always returns me with a wrong month. I
>> have tried to use DateUtil, but can't find a way to apply it.
>>
>> My method is as follows and I appreciate the support.
>>
>> public static String cambiaNumeroFecha(Long fecha) {
>> Calendar c = Calendar.getInstance();
>> Date d = new Date(fecha);
>>
>> String r = Integer.toString(c.get(Calendar.YEAR)) + "-"
>> + Integer.toString(c.get(Calendar.MONTH)) + "-"
>> + Integer.toString(c.get(Calendar.DAY_OF_MONTH));
>> return r;
>> }
>>
> --
> You received this message because you are subscribed to the Google Groups
> "CodenameOne Discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/codenameone-discussions/e9bf0310-47d8-4bcd-b9fe-dce771e3f0c6n%40googlegroups.com
> <https://groups.google.com/d/msgid/codenameone-discussions/e9bf0310-47d8-4bcd-b9fe-dce771e3f0c6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/CAG90yJ2uYS9UQixb%2BSRa3YrWvLFq7B%3DLfY4jV21vz_%3DmG_uByg%40mail.gmail.com.