Notice that date in milliseconds is in GMT/UTC so it should work well universally even if your server is in a different time zone (which is very likely). That's probably the source of the problem you're experiencing. This is why the response from Javier should work as it removes the time/location from the date and focuses on the calendar day.
On Monday, June 21, 2021 at 9:39:50 AM UTC+3 [email protected] wrote: > 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/e93ea1c2-98fd-4e89-bf87-56896c6e1884n%40googlegroups.com.
