Answer the question
In order to leave comments, you need to log in
How to get date separator?
How to determine date separator if possible separators are '.', '/', '-' ? The time separator is always ':' so we skip it.
I'm currently using split to split the string and check it 3 times for each of the above characters. I would like to know if this can be done in one step? If so, how?)
Answer the question
In order to leave comments, you need to log in
The separator is the first non-numeric character. So . str.match(/\D/)[0]
Often it is enough just to feed the string into new Date() or Date.parse() it takes as input with different delimiters.
If you know the format, you can use moment.js , the format is specified there.
Example:
moment("2010-10-20 4:30", "YYYY-MM-DD HH:mm"); // parsed as 4:30 local time
moment("2010-10-20 4:30 +0000", "YYYY-MM-DD HH:mm Z"); // parsed as 4:30 UTC
'2008/07/06',
'07-06-2008',
'06-07-2008',
'07/06/08',
'06/07/08',
'07/06/08',
'06/07/08',
'08/06/07',
how do you tell them apart without knowing the format?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question