Jump to content

PHP and date (json)

Recommended Posts

I'm still learning everything...literally. Alfred, php, json. I managed to finally get my workflow to POST to my Planka kanboard as a new card. However, I'm now trying to get the card's "due date" populated. For that I need it in json format like this:


$dueDate = "2022-03-12T21:00:00"


Bsically, how can I make $dueDate dynamic based on Now and Los Angeles?


The above works but obviously I need that to be Now (and ideally as Americas\Los_Angeles). The only stuff I can find is to add a class to my script---but I wasn't able to get that to work. Hoping someone has done this before and can just copy/paste something that magically works. Hope I'm asking this right---I'm a bit confused after googling.



Link to comment
  • 2 months later...

The JSON specification does not specify a format for exchanging dates which is why there are so many different ways to do it.  JSON does not know anything about dates. What .NET does is a non-standard hack/extension. The problem with  JSON date and really JavaScript in general – is that there’s no equivalent literal representation for dates. In JavaScript following Date constructor straight away converts the milliseconds since 1970 to Date as follows:


var jsonDate = new Date(1297246301973);


Then let’s convert it to js format:


var date = new Date(parseInt(jsonDate.substr(6)));


The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .


Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...