php 如何从 Laravel 的 created_at 列中提取月、日?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45138724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to extract month, day from created_at column in Laravel?
提问by Azima
I want to display something like 01 June from created_at column. I tried doing something like this which I know, is quite dumb thing.
我想从 created_at 列显示类似 01 June 的内容。我试着做这样的事情,我知道,这是很愚蠢的事情。
<span class="day">{{date('m', $new->created_at)}}</span>
回答by Exprator
{{ $object->created_at->format('d M') }}
for day and month
日和月
{{ $object->created_at->format('M') }}
for only month
仅一个月
{{ $object->created_at->format('d') }}
for only day
只有一天
$object
referred to your passed variable from the controller to the blade
$object
引用您从控制器传递到刀片的变量
回答by Sagar Gautam
回答by Arpit J.
$timestamp = strtotime($new->created_at);
//Uppercase letters gives day, month in language(Jan, Third, etc)
$day = date('D', $timestamp);
$month = date('M', $timestamp);
//lowercase letters gives day, month in numbers(1, 3, etc)
$day = date('d', $timestamp);
$month = date('m', $timestamp);
//use a combination of both, eg: 01 June
$final_Date = date('d', $timestamp) .' '. date('M', $timestamp);
回答by Karthik
$timestamp = strtotime($new->created_at);
$day = date('D', $timestamp);
$month = date('M', $timestamp);
回答by Th3
use
用
echo date('d M',$new->created_at));
For manipulation of date & time you can go through http://php.net/manual/en/function.date.php
要操作日期和时间,您可以通过http://php.net/manual/en/function.date.php