I originally posted this post on my blog.
Is it MM
or mm
for months when formatting dates? Is it "yyyy-MM-dd"
or "yyyy-mm-dd"
?
I always forgot which one to use...Until I figured out an easy mnemonic.
MM vs mm
Ask yourself: Which one represents a larger time frame? Months or minutes?
Since one month is larger than one minute, it's M
for months. An uppercase m is larger than a lowercase m.
Write, anyDate.ToString("yyyy-MM-dd")
.
mm vs fff
Then, what is it for milliseconds? Isn't it mm
?
Now, ask yourself: Which one is faster? One minute or one millisecond?
Since one millisecond is faster, write f
.
Write anyTime.ToString("hh:mm:ss.fff")
.
Easy, peasy now!
Join my email list and get a 2-minute email with curated resources about programming and software engineering every Friday. Don't miss out next Friday email.