Skip to main content

All Questions

Tagged with
-1 votes
1 answer
159 views

Format path with date placeholders

Is there a way to insert date parts into a path containing date formats? I've got an application that should save files into yearly & monthly folders, but I'd rather not hardcode it. The current ...
t3chb0t's user avatar
  • 18.9k
13 votes
2 answers
4k views

Java 21 problem with DateFormat.getDateTimeInstance().format(new Date())

This is my code import java.util.Date; import java.text.DateFormat; class DateTime { public static void main(String[] args) { String dt = DateFormat.getDateTimeInstance().format(new Date()...
Spencer Shellman's user avatar
1 vote
4 answers
377 views

How to convert UTC date and time format to zone time format?

I have a method which generates a random date and time. import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.Period; public String getRandomFormattedDateAndTime() { ...
Jeff's user avatar
  • 8,469
0 votes
1 answer
1k views

How to guarantee 2 digit month in Java without using formatting string literals?

I'm not sure if this will always issue a 2 digit month: java.time.LocalDateTime ldt = java.time.LocalDateTime.now( java.time.ZoneId.of( "America/New_York" )); String path = "my/path/&...
Kenobi's user avatar
  • 495
0 votes
2 answers
241 views

Is there a format string for SimpleDateFormat to get milliseconds date-time value instead of human-readable form?

By means of classes like SimpleDateFormat it is possible to format time and date in a suitable format. Examples here https://developer.android.com/reference/java/text/SimpleDateFormat#examples In ...
P5music's user avatar
  • 3,337
1 vote
1 answer
6k views

Format OffsetDateTime converted from JAXBElement<XMLGregorianCalendar>

I am trying to convert the JAXBElement-XMLGregorianCalendar to offsetDateTime. I am able to do that but I want to convert the date in a particular format. Code I am using to convert: calendarValue is ...
Roopam Gupta's user avatar
-1 votes
2 answers
850 views

Java - Date format for Multiple Scenarios

I have a java component to format the date that I retrieve. Here is my code: Format formatter = new SimpleDateFormat("yyyyMMdd"); String s = "2019-04-23 06:57:00.0"; ...
Anto's user avatar
  • 3
27 votes
2 answers
44k views

UnsupportedTemporalTypeException: Unsupported field: InstantSeconds

I have this code which is producing a timestamp and then parsing. DateTimeFormatter formatter = DateTimeFormatter .ofPattern("yyyyMMdd kk:HH:ss.SSSZ") .withLocale(Locale....
Steve's user avatar
  • 792
3 votes
3 answers
2k views

Java 8 DateTime Format Date + Offset

I have to construct a XMLGregorianCalendar for a Webservice which expects a date in the format yyyy-MM-dd+01:00, where the value after + is derived from the time zone offsett. So far I have ...
Hans's user avatar
  • 165
2 votes
2 answers
7k views

DateTime format both Zulu and Offset

I want to have one single date time pattern expression to be able to: Serialize date/instant with offset indicator, eg: 2017-07-13T21:20:33.123+0000 Parse string with zulu indicator, eg: 2017-07-13T21:...
Robin Jonsson's user avatar
1 vote
1 answer
3k views

How is this int formatted to represent date and time?

I am studying a method I have found in an application called 'getDateTime'. It returns a date and time as one integer. This is then converted by the app and displayed on a label in 24 hour format. I ...
Freddie's user avatar
  • 21
0 votes
1 answer
627 views

DateUtils getRelativeTimeSpanString always returning same Date

Following problem: Log.d(getClass().getName(), String.valueOf(c.getTime())); //c.getTime() returns a long value CharSequence timeAgo = DateUtils.getRelativeTimeSpanString( c.getTime()...
F.Zw.'s user avatar
  • 41
2 votes
2 answers
1k views

Java: SimpleDateFormat not formatting in desired TimeZone

I would like to format dates, for a specific time zone, GMT, and I want the result of that formatting to be the same always, regardless of which time zone the application runs in. E.g., create ...
Alex Averbuch's user avatar
8 votes
1 answer
4k views

Java 8 DateTimeFormatter dropping millis when they're zero?

This seems weird. Java 8 is formatting the output differently depending on whether the millis is zero. How do you force Java 8 (1.8.0_20) to always spit out the millis regardless of if they're zero or ...
Chris Kessel's user avatar
  • 5,875
1 vote
0 answers
156 views

Joda DateTimeFormat change AM/PM format? [duplicate]

It formats 'aa' as "AM"/"PM", but I want "a.m."/ "p.m.". Is this possible with the formatter, or is my best bet to manually do a .replace()? Thanks.
Basil's user avatar
  • 403

15 30 50 per page