Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
Converting date from JSON response in PHP

I am getting the following date format from a JSON response and want to format it better, but I am a little unsure how to.

Current Response: Wed Mar 02 03:00:00 +1100 2016

Required Response: 2nd of March 2016

Current PHP for output:

$purchase_data['verify-purchase']['supported_until']
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

some speacial formatting here, but possible when reading the manual. also take care of time zone…

<?php

//custom function
function reformatDate( $old, $correction ) {
    // makes it a number of seconds since 1970…
    $old_date_timestamp = strtotime( $old ); 
    //formats again as string
    return date( 'jS F Y', $old_date_timestamp + $correction ); 
}

//Input: Wed Mar 02 03:00:00 +1100 2016
//timezone needs to be taken care of
print reformatDate(
  "Wed Mar 02 03:00:00 +1100 2016", //here you put your input variable
  11*60*60 // here 11h, but maybe the difference of timezones needs to be changed – only you will know after edge cases ;)
);
//desired output: 2nd of March 2016 – check

?>

to do it even better you could ask your own timezone from the local setting. date can help you there as well, or you go by timezone_offset_get to automate that … the latter is more tricky as it raises an error when not set before.

over 4 years ago · Santiago Trujillo Denunciar

0

Try this out:

$old_date_timestamp = strtotime($purchase_data['verify-purchase']['supported_until']);
$new_date = date('d F Y', $old_date_timestamp);
print $new_date;
over 4 years ago · Santiago Trujillo Denunciar

0

Someone posted an answer on here but for some reason was deleted, however i used some of their solution and adapted and created into a function so for anyone else needing to handle a returned date formatted in such a way here is what i done.

function dateFormat($date){
    $current_date = $date;
    return date("jS", strtotime($current_date) ) . ' of ' . date("F Y", strtotime($current_date) );
}

Then called it like so....

dateFormat($purchase_data['verify-purchase']['supported_until']);

Output went from:

Wed Mar 02 03:00:00 +1100 2016

To:

1st of March 2016

Actually noticed now writing this, it is rounding off to 1st rather than 2nd?

UPDATED

Updated with answer from @vv01f to correct the date, here is the final result

function dateFormat( $old, $correction ) {
    $old_date_timestamp = strtotime( $old );
    return date( 'jS F Y', $old_date_timestamp + $correction );
}

Calling it like so...

dateFormat($purchase_data['verify-purchase']['supported_until'], 11*60*60); 
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda