Reputation: 1940
Using Java String.format() how do I format a string to result in "Time - userId" (ie. 3:02 pm - joe user).
I have worked several iterations, and I think it is the space between the minutes and the am/pm that is throwing me off. My last iteration is
String.format("%1$tl:%1$tM %1$tp - %2s", new Date(), "joe user");
I am about to punt and use a SimpleDateFormat, but thought I would ask here first.
Upvotes: 4
Views: 3489
Reputation: 274522
You need %2$s
to get the second argument, as shown below:
String.format("%1$tl:%1$tM %1$tp - %2$s", new Date(), "joe user")
prints:
4:56 pm - joe user
Upvotes: 7