Skip to content

Commit

Permalink
Refined previous change to address comments
Browse files Browse the repository at this point in the history
Will handle times like 10:00AM, 10:00 AM and 10:00.

Based on this thread: https://www.reddit.com/r/cn1/comments/y6bdhq/date_time_formatting/
  • Loading branch information
shai-almog authored Oct 27, 2022
1 parent ca4bfe8 commit f8a7c5c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CodenameOne/src/com/codename1/l10n/L10NManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ public String formatDateTimeMedium(Date d) {
*/
public String formatTime(Date d) {
String s = formatDateTimeMedium(d);
s = s.substring(s.lastIndexOf(" ") + 1);
int pos = s.lastIndexOf(" ");

// this can be just the AM or PM
if(s.length() - pos < 4) {
pos = s.lastIndexOf(" ", pos - 1);
}
s = s.substring(pos + 1);
return s;
}

Expand Down

0 comments on commit f8a7c5c

Please sign in to comment.