Get current time - bug in date format

I noticed you can connect a “now” panel to a time component and you get a formatted date and time.

So I noticed that the format is outputs is actually wrong. It shows the 13th as 13rd!? And I though its using some script to do the conversion from a timestamp to a standard format, but apparently somebody missed this huge error.

date_time

Also was looking for a way to reformat the time, but there doesn’t seem to be an easy way, since even deconstruct date outputs a very specific format, like not outputting zeros in front of the days and months and so on.

So I am curious is there a way to just have a date component where you simply input the time format you want and it outputs that? Like maybe it could use the culture input like in the Text Case component and use those formats here: https://docs.microsoft.com/de-de/dotnet/api/system.datetime.tostring?view=netframework-4.8 or just use a custom format similar to how strftime works in PHP or others.

Does the time component with “now” internally output a time stamp or only the formatted date and time?

I love how sometimes you ask a question here and then you kind of get inspired to solve it yourself. I just looked up how to do it in Python and violas it works great even with no Python skills.

I include the list with all the formats with examples in case anybody ever needs this. Great for creating file names for exporting objects using Elefront or for ShapeDiver.

python_current_time.gh (7.4 KB)

4 Likes

Oops, 3 = “rd”, 23 = “rd”, 33 = “3d”, … but I forgot that 13 needs needs a “th”.

1 Like

It outputs a System.DateTime instance which is an object which counts the number of ticks (1 tick = 100 nanoseconds) since January first, the year 1 according to the Gregorian calendar. The formatting of dates and times only happens inside tooltips and when you specifically convert the data to text. And since it’s my code there’s a bug in the ordinal suffix string selector.

eh, Deconstruct Date outputs integers, without any formatting being involved anywhere.

oh yeah, sure, that makes sense actually, as it would be a string in that case. My bad…

And you can format a date using the Format component:

2 Likes

Touché :smiley: