当前位置: 动力学知识库 > 问答 > 编程问答 >

datetime - php date time function

问题描述:

I want to convert this date ( 02-12-2010) mm-dd-yyyy to time format

ie

to 02-12-2010 0 hours 0 minutes and 0 seconds

i have user time and date functions but when i refresh the page its value is changing as per the time.

i need that to be fixed

also i want to convert this date (01-24-2009) to time format.

please help me

Thanks

网友答案:

Use the strtotime function to convert an existing date/time string into a timestamp for the date function.

$new_date = date('m-d-Y h:i:s', strtotime('02-12-2010'));

The reason that your date keeps updating with the current time is that the date() function uses the current system's timestamp by default when no second parameter is provided.

网友答案:

Use the date_parse_from_format () API function to transform your given format to an array. E.g.

$date = "02-12-2010";
$dateArr = date_parse_from_format("d-m-Y", $date);

Output it with something like:

$output = $dateArr['day'] . '-' . $dateArr['month'] '-' . $dateArr['year'];
网友答案:

You can use the strtotime function eg:

$mydate = date('m-d-Y h:i:s', strtotime('02-12-2010'));
分享给朋友:
您可能感兴趣的文章:
随机阅读: