#2519 Date/Time toLocale support for single quote literal

SlimerDude Mon 4 Apr 2016

Date.toLocale() works like this:

Date.today.toLocale("MMM YYYY")  // --> Apr 2016

and I can even add my own literals:

Date.today.toLocale("MMM 'T' YYYY")  // --> Apr T 2016

But how do I add / escape the apostrophe literal ' ?

I'd like to accomplish the following:

Date.today.toLocale("MMM ??? YY")  // --> Apr '16

Any ideas? Apart from, that is, splitting up the code:

Date.today.toLocale("MMM") + " '" + Date.today.toLocale("YY")

Cos that's pretty horrible!

brian Wed 6 Apr 2016

What does Java do? I guess we could copy their handling since that is where the single quote came from originally

SlimerDude Wed 6 Apr 2016

Java's SimpleDateFormat uses double apostrophies:

Text can be quoted using single quotes ('') to avoid interpretation. "''" represents a single quote.

You can see it used in the examples:

"EEE, MMM d, ''yy"  -->  Wed, Jul 4, '01

brian Wed 4 Oct

Ticket promoted to #2519 and assigned to brian

brian Wed 4 Oct

Ticket resolved in 1.0.70

Enhanced Date, Time, DateTime fromLocale/toLocale to use to mean single quote like Java does

Login or Signup to reply.