Manaus Posted July 8, 2023 Share Posted July 8, 2023 I'm querying 3 pages, with this code: <?php function dateToItalian($unixtimestamp) { setlocale(LC_TIME, "it_IT.utf8"); return ucwords(strftime("%a %d %B %Y", strtotime($unixtimestamp))); } ?> <?php foreach ($page->children as $child): ?> <p> <?php echo $child->created." "; echo dateToItalian($child->created); ?> </p> <?php endforeach ?> I get this: 1685722140 Thu 01 January 1970 1685723334 Thu 01 January 1970 1662705715 Thu 01 January 1970 Anyone can explain why? Link to comment Share on other sites More sharing options...
Robin S Posted July 8, 2023 Share Posted July 8, 2023 I can see a couple of problems. 4 hours ago, Manaus said: strtotime($unixtimestamp) The purpose of strtotime() is to "Parse about any English textual datetime description into a Unix timestamp". But you are supplying it with a variable that is already a Unix timestamp. So that will cause strtotime() to fail and return false. And then that false return value is then being supplied to strftime(), which instead needs to be supplied with a Unix timestamp. Also not sure that ucwords() would be needed, as I think the date string returned by strftime() should already be capitalised correctly. So probably it should be this: function dateToItalian($unixtimestamp) { setlocale(LC_TIME, "it_IT.utf8"); return strftime("%a %d %B %Y", $unixtimestamp); } 4 Link to comment Share on other sites More sharing options...
monollonom Posted July 9, 2023 Share Posted July 9, 2023 Also note that strftime has been deprecated in PHP 8.1. Here’s a topic with alternatives: 1 Link to comment Share on other sites More sharing options...
zoeck Posted July 9, 2023 Share Posted July 9, 2023 Of Just use the newest PW DEV Version ? 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now