I seem to be using strftime wrong

I can create an action with a single script step containing:

strftime(Date(), "%Y");

and when I run it Drafts instantly crashes. (Drafts 25.1.4, both iPadOS 14.4 beta 2 and iOS 14.3). First, does this work for other people? If not, how should I be calling the function? The docs are pretty straightforward and wouldn’t seem to leave a lot of room for error.

Try this.

let dt = new Date()
alert(strftime(dt, "%Y"));

I’ll fix the crash…the app should capture for invalid values.

But the reason is that Date() does not return a Date object in JavaScript. It returns a string. You need to use new to instantiate an object of Date type.

@sylumer’s example works, or just strftime(new Date(), "%Y"); should be fine as well.

1 Like

That did it. Thanks!

Huh, TIL a little more about JavaScript. I’m coming from a Python background and know just enough JS to get by.

1 Like