All Questions
46 questions
-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 ...
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()...
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() {
...
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/&...
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 ...
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 ...
-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";
...
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....
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 ...
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:...
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 ...
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()...
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 ...
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 ...
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.