Comments (14)
Here's my test code:
$timestamp = strtotime("2014-01-02");
echo date("nS", $timestamp); // month number
echo date("jS", $timestamp); // day-of-month
echo date("zS", $timestamp); // day-of-year
echo date("wS", $timestamp); // day-of-week
echo date("WS", $timestamp); // week-number-of-year
from moment.php.
One last thing:
'DDDD' should convert to 'z' not 'zS'
from moment.php.
Hey there.
Thanks for the note. I'll have a look for the correct transformations but that wont happen until next week. Would be great if you could figure out the correct formats and push them - in case you have some time.
Cheers
Tino
from moment.php.
I'll see what I can do. Unfortunately there aren't any ordinal suffixes for anything but the day-of-the-month in PHP (as far as I can tell) so they (the suffixes) may have to be dropped during the conversion.
from moment.php.
echo date('dS M Y'); // 13th May 2014
Thats what u want, right?
from moment.php.
Ah, I see. U want something like:
265th day of the year
correct?
from moment.php.
Well, it's not so much that I want it but rather that Moment.js supports that and PHP doesn't so you can't convert between the two. The 'S' in PHP is for day-of-the-month ONLY. There are no ordinal suffixes for day-of-the-year. This means that the aforementioned conversions don't work.
from moment.php.
But yes, it seems (as far as I can tell) getting something like:
265th day of the year
... is impossible in PHP using date formats.
from moment.php.
You can do this with PHP.
If you know it's the 265th day of the year you want, you really only care about the 5 to get the correct S value.
To get "th" you can use:
date( 'S', strtotime( '2014-01-05' ) );
If you wanted to get an "st" you can use:
date( 'S', strtotime( '2014-01-01' ) );
from moment.php.
Thats what we want then:
https://gist.github.com/mnbayazit/6195925
from moment.php.
Perhaps I'm missing something, but that doesn't seem to solve the issue because we don't know what day it is. This issue is dealing with converting a moment.js date format string to a PHP date format string.
i.e.
Mo -> nS
The problem with this is that 'nS' won't give you the correct ordinal suffix (at least not always, see OP).
from moment.php.
Ok, I am just shooting quickly here but we have to do some logic here.
If the user requests something with "o" I know that he wants some ordinal shizzle.
"Mo" goes for the ordinal month. So if we parse for these formats we know what we need to deliver and can simply service it, right?
"Mo" stands for month so we run in php "m" through the aforementioned function which would result in "05th" instead of only giving us back "05".
Again, I am really just going by feeling right now since I am busy with some other stuff.
Looks cool to me at the moment. What u think?
Cheers from Berlin
from moment.php.
Yes, if you want ordinal suffixes for anything other than day-of-month you need extra logic. But that seems out of scope for the MomentJS.php class since it only handles format strings and not the dates themselves.
SO, with regard to the MomentJS.php class: what should these conversions be?
Moment.js | PHP |
---|---|
Mo | ??? |
Do | jS |
DDDo | ??? |
do | ??? |
wo | ??? |
Wo | ??? |
from moment.php.
version 1.5.0 has this now. just released it.
from moment.php.
Related Issues (20)
- getRelative time is broken in many cases HOT 5
- Seemingly valid RFC2822 returned as invalid HOT 1
- fix missing getRelative 'ss' in many locales HOT 1
- we need a proper date validation HOT 2
- need to fix relativeTime strings for Hungarian
- Declaration warning - PHP 7.1.22 HOT 1
- Lost functions vs moment js HOT 1
- getRelative() returns "0 years ago"
- IsBetween error function HOT 2
- Slovak Translation HOT 2
- Incorrect timezone parsing W3C + DTS
- builds failing due to PHP 5.x errors HOT 1
- Please add support all the way to Microseconds
- MomentJS format needs locale based adjustments
- Get unrounded date diff
- PHP Deprecated
- fetchSimilarLocales: All-lowercase Accept-Language header doesn't work
- ADD recognize weeks
- createFromFormat not compatible - PHP 8 HOT 2
- Moving to 2.0.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moment.php.