Skip to content

Instantly share code, notes, and snippets.

@jpcercal
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save jpcercal/05001ccae00d5c6ae216 to your computer and use it in GitHub Desktop.

Select an option

Save jpcercal/05001ccae00d5c6ae216 to your computer and use it in GitHub Desktop.
Create date from string
<?php
setlocale(LC_ALL, NULL);
setlocale(LC_ALL, 'pt_BR');
$time = "segunda-feira, 28 de julho de 2014 10h10min07s UTC-3";
$timeParts = explode(',', $time);
$timeParsed = strptime(
end($timeParts),
'%d de %B de %Y %Hh%Mmin%Ss'
);
$createdAt = date('Y-m-d h:i:s', mktime(
$timeParsed['tm_hour'],
$timeParsed['tm_min'],
$timeParsed['tm_sec'],
1,
$timeParsed['tm_yday'] + 1,
$timeParsed['tm_year'] + 1900
));
echo $createdAt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment