use conventional syntax for formatting #49

defunctzombie opened this Issue Nov 10, 2011 · 5 comments


None yet
4 participants

I don't know why you invented your own format specifiers, but things like stftime (and that family of methods) have a well known set of format specifiers. Would be nice if you could just use those instead of making new ones which won't match up to what someone may already be using.


timrwood commented Nov 10, 2011

There are too many different date format tokens syntaxes for me to match any standard.

See this comment. timrwood#36 (comment)

That explains my rationale for why I chose the tokens I did.

@timrwood timrwood closed this Nov 10, 2011

I would think using the strftime notation would be quite reasonable as it would be found on all platforms in some form. The fact that things like unix, python, php, ruby, c/c++, etc all support it should tell you something :)

When looking for a simple date library to use over the builtin one, I would pick something that mimics strftime or just not bother personally.


timrwood commented Nov 11, 2011

The intention of this library is not to port strftime. It is to provide a safe and robust collection of common functionality regarding dates.

There are many implementations of strftime in javascript. A brief search on github found the following:

I'm not too experienced with formatting dates in unix, python, ruby, or c++, but I know php has both strftime and date for formatting dates, and the tokens for those functions vary wildly.

As described in the comment I linked to above, the reason I chose the tokens I did was to aid readability. I believe the tokens I chose would be much easier to remember or deduce than strftime tokens for someone who hasn't been exposed to either.

I don't mean to start an argument, hopefully you can understand my rationale for designing the library this way.

To revive a very old topic. I'm going to end up using the moment-strftime/moment-tokens library, simply because I need interoperability with Django's internationalisation code. Here's an example of some (admittedly horrible) JavaScript generated by the framework to aid in client-side internationalisation:

As you can see, it exposes the strftime syntax for date/time/datetime formatting, which the client-side code can use at will.

Not trying to reverse your decision, since your reasoning makes sense to me, but just providing a use case.

butterflyhug pushed a commit to WhoopInc/frozen-moment-OLD that referenced this issue Jul 22, 2014

henrik commented Aug 27, 2015

moment-strftime link for reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment