"simple" Dates one line question

using Dates;  # somewhere at the top of your file or module
Dates.format(now(), DateFormat("e dd u yyyy I:MMp"))

does almost what you want, but this actually more tricky than I though, what I came up with is:

n = now(); Dates.format(n, DateFormat("e d u yyyy I:MM ")) * lowercase(Dates.format(n, DateFormat("p")))

It’s my preference to use d, not dd, i.e. show 1 Jan, not 01 Jan, but the latter is better if you need to show in a table for alignment (you can use either when parsing). Your call. And you asked for pm, not PM and I found no other way to do this…

Note do NOT do redundant now(). They might not return same now, i.e. the first could do just before midnight and the other just after…

I see Java shows with lower case, as you asked for:

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/FormatStyle.html

p is case sensitive on input, and it may be intentional to be upper-case on output. It’s not wrong, PM and AM are acronyms after all…, it’s just pm and p.m. is rather commonly used… Your call if you like it spaced or not, maybe space isn’t preferred.

I can parse PM, spaced or not, but only either, not the both with the same format string, at least in Julia…, so consider what you do there. I use spaces since it’s not wrong, at least in some contexts (e.g. Wikipedia, then non-break space even better). It’s not too hard to output with the periods, actually often wanted, but I wouldn’t figure out how to parse such strings…

[Some other languages use a rather than p for the format string, and since it’s not used, maybe it could be for compatibility, and then be used to output in lower-case. It would be a slight breaking change, but who would want a a try a anyway on output…]

And with DateFormat rather than a naked string is slightly faster, e.g. in a loop. I like to say I’m neither an expert (on Julia), but maybe I’m getting there on this point… :slight_smile:

Do use yyyy, not yyy, as I did at first incorrectly or yy. I was testing it out, and it will not be good for input that way, at least in Julia… I was trying to fix that, but my PR wasn’t accepted…