0

I would like to convert a java.util.Date to something more user friendly using PHP. Is there a way of doing this using PHP?

I tried doing something like:

$created = date("F j, Y, g:i a", $issue_fields['created_date']);

but it complained with an error that looks like:

Notice: A non well formed numeric value encountered in C:\wamp\www\PHP\get_tickets.php on line 49

Unfortunately, I don't have control over the date format I received. The format looks like:

2013-01-22T11:46:24.000-0800

and I would like something more like September 24, 2011, 6:39 am. Is this possible?

Thanks!

KyelJmD
  • 4,682
  • 9
  • 54
  • 77
Marco A
  • 109
  • 1
  • 2
  • 10
  • 1
    possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) - you are using `date()` incorrectly. It takes a unix epoch time as its second argument. – Brian Roach Feb 22 '13 at 01:25

2 Answers2

2

It looks like the given date is in ISO 8601 format. You should be able to convert this to a date object using strtotime:

echo date("F j, Y, g:i a", strtotime('2013-01-22T11:46:24.000-0800'));

This yields: January 22, 2013, 11:46 am

Zack
  • 1,181
  • 2
  • 11
  • 26
0

You can use date_parse_from_format().

Clyde
  • 7,389
  • 5
  • 31
  • 57
  • @BrianRoach You must have a different idea of what he wants than me then. He wants to parse a date/time string, as I understand it. Converting it to another format is another step, but one that should be fairly obvious once he reads the docs. – Clyde Feb 22 '13 at 01:35
  • Actually reading his question led me to that idea. His *entire question* is asking how to convert one to another. – Brian Roach Feb 22 '13 at 01:37