[TW5] From a formated date to a day, a month and a year ?

96 views
Skip to first unread message

FrD

unread,
May 11, 2017, 1:03:25 PM5/11/17
to TiddlyWiki
Hi,

Context : I'd like to re-write my datepicker plugin that goes along with the simplecalendar plugin.

When you want to turn 3 numbers (one for the day, one for the month and one for the year) into a string according to a format, you can use a built-in function :

var d = new Date(year, month-1, day);
return $tw.utils.formatDateString(d, format || "DDth MMM YYYY");

And I was wondering how to do the other way round, getting the three numbers from a string and the format that was used to build the string.
Has this been already done ? Even in a limited way for formats used in most cases ?

Thanks in advance

FrD

PMario

unread,
May 11, 2017, 7:47:14 PM5/11/17
to TiddlyWiki
Hi,

With the js system functions you should be able to get what you want.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date

-m

FrD

unread,
May 12, 2017, 1:36:47 AM5/12/17
to TiddlyWiki
Hi PMario,

I'll have a look.

Thanks

FrD

unread,
May 12, 2017, 6:57:44 AM5/12/17
to TiddlyWiki
Hi,

I didn't find anything useful with the js date object.

I think I'll end writing a js macro that find the index of "0DD" or "DD" in the format string and extract it from the date string. To get the month will be a bit more complicated as it can be a number or a name, but not so much.

FrD

PMario

unread,
May 12, 2017, 7:07:44 AM5/12/17
to TiddlyWiki
Imo you can throw almost any string at Date.parse() or "new Date" and convert it to a js date object. Which then can be used with the tw utility function.

just some thought.

-m
Reply all
Reply to author
Forward
0 new messages