Closed freshchen closed 8 months ago
Date filter already supports Temporal and older java.util.Date, so it should cover almost all use cases.
e.g.: variables:timestamp=1709564462 template:{{ timestamp | date(... ...) }} output:2024-03-04 23:01:02
I didn't find it in the test case. After looking at the code, I still don't know how to use DateFilter to achieve the above effect. Can you help tell me how to configure it?
Just use {{ timestamp | date("MM/dd/yyyy HH:mm:ss") }}
. It's just plain SimpleDateFormat syntax ... not pebble related
The Date constructor accepts milliseconds by default, so it does not support the second timestamp that is more commonly used in real life. This is very unintuitive for non-java programmers
If no changes are made, for date processing I have to define another timestamp filter to convert the timestamp into a millisecond timestamp, which is very troublesome to use.
The same goes for converting a formatted date into a timestamp with different time units.
You can use any Temporal date too ... such as a LocalDate, LocalDateTime, ZonedDateTime etc.
Ok got it. I will add existingTimestamp parameter to my project
Converting dates and timestamps to and from each other is very common.
I want to discuss whether we can add optional values about timestamps in format in DateFilter(format,existingFormat)
e.g.: {{ time | date(existingFormat='yyyy-MMMM-dd', format='timestamp') }} {{ time | date(existingFormat='timestamp', format='yyyy-MMMM-dd') }}
optional values: timestamp timestampMillisecond