PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 31, 2021

[FIXED] Cakephp 3: How to format day with i18nformat

 December 31, 2021     cakephp, cakephp-3.0, datetime, html, php     No comments   

Issue

this might be a simple question but honestly the cookbook's documentation on this is quite scarce and I can't find anything online.

I've got a database that is storing the time in timestamp format, and when I retrieve it I'm trying to show in a different format. I've got everything to show as I want to apart of the day.

date->i18nFormat('dd-MM-yyyy H:mm:ss')

See, I'm trying to show nd / rd / th next to the day number. All I can find is jS but when I use it nothing shows up.

Is there any other way? Thanks.


Solution

jS is a standard PHP date format pattern, but Time::i18nFormat() is for localizable dates, and it uses the INTL date formatter, which makes use of ICU formatting patterns, which have no support for ordinals (probably because most languages don't have them).

So if you don't actually need to create localizable output, use the regular PHP date formatter via the format() method inherited from \DateTime / \DateTimeImmutable:

$date->format('F jS, Y H:i:s');

See also

  • Cookbook > Date and Time > Formatting
  • PHP Manual > Function Reference > Date and Time Related Extensions > Date/Time > DateTimeInterface


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing