- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 jQuery 日历以如下形式输入日期
<div class="form-group">
<label>Valid From:</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" tabindex="4" data-date-start-date="0d" class="form-
control pull-right datepicker" name="valid_from" id="datepicker2" value="
{{old('valid_from')}}">
</div>
@if ($errors->has('valid_from'))
<span class="has-error" style="color: red">
<strong>{{ $errors->first('valid_from') }}</strong>
</span>
@endif
</div>
我从表单中获取 09-03-2018 形式的值。
模型代码,我尝试用 mutator 转换它,但它对模型代码不起作用
use SoftDeletes;
protected $fillable =
['name','valid_from','valid_to','city_id','p_limit','is_active','type'];
protected $dates = [
// 'valid_from',
// 'valid_to',
'deleted_at'
];
// public function setDateOfBirthAttribute($dates)
// {
// $this->attributes['valid_from'] = Carbon::parse($dates);
// $this->attributes['valid_to'] = Carbon::parse($dates);
// $this->attributes['deleted_at'] = Carbon::parse($dates);
// }
// protected function getDateFormat()
// {
// return 'U';
// }
// protected function getDateFormat()
// {
// return 'd-m-Y ';
// }
// public function setFirstNameAttribute($dates)
// {
// $this->attributes['valid_from'] = strtotime($dates);
// $this->attributes['valid_to'] = strtotime($dates);
// $this->attributes['deleted_at'] = strtotime($dates);
// }
// public function getValidTillValueAttribute($date)
// {
// return Carbon::now()->toRfc2822String($date);
// }
// public function setValidTillValueAttribute($value)
// {
//// $this->attributes['valid_to'] =
Carbon::createFromTimestamp($value);
// $this->attributes['valid_to'] = strtotime($value);
// dd($value);
// }
// public function setValidFromValueAttribute($value)
// {
// dd($value);
//// $this->attributes['valid_from'] =
Carbon::createFromTimestamp($value);
// $this->attributes['valid_from'] = strtotime($value);
// }
Controller 代码
public function store(PromotionRequest $request)
{
$input = $request->all();
// return $request->all();
$date = $request->valid_from;
$date1 = $request->valid_to;
$_newDate = strtotime($date);
$_newDate1 = strtotime($date1);
// dd($_newDate);
// dd($_newDate1);
// return $input;
// return $_newDate1;
// return $_newDate;
// dd($request->all());
// return $request->$_newDate;
// return $request->$_newDate1;
Promotion::create($input,$_newDate,$_newDate1);
// Promotion::create($input);
// return redirect('admin/promotion');
}
迁移代码
$table->increments('id');
$table->string('name')->unique();
$table->integer('valid_from');
$table->integer('valid_to');
$table->tinyInteger('is_active')->comment('0 = Not Active, 1 = Active');
$table->tinyInteger('type')->comment('1 = percentage, 2 = in currency');
$table->integer('city_id')->default(1)->comment = "foreign key to cities
table";
$table->integer('p_limit')->unsigined();
$table->integer('updated_at')->unsigined();
$table->integer('created_at')->unsigined();
$table->integer('deleted_at')->unsigined()->nullable(true);
$table->foreign('city_id')->refrences('id')->on('cities');
我想将它转换成 unix_timestamp 任何帮助将不胜感激
最佳答案
您可以使用 strtotime()
这是一个例子
strtotime('09-03-2018');
另一种方法是使用碳
Carbon::parse('string')->timestamp;
还要确保你的模型在 $fillable 数组中有这些键
$fillable = ['your colums'];
在你的 Controller 中你这样做
$input['valid_from'] = strtotime($date);
$input['valid_to'] = strtotime($date1);
Promotion::create($input);
希望对你有帮助
关于laravel - 如何在 laravel 中将输入字符串转换为 strtotime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49067043/
在 PHP 中对 strtotime() 进行了一番研究之后,我注意到当您传入空格和/或点时,它会返回一个有效的时间戳。 var_dump(strtotime(" ")); var_dump(strt
这是我的代码: $testtime = str_replace('.', '-', '2009.07.08 17:01'); $timestamp = strtotime($testtime); ec
我有一个脚本,它从 excel 表中读取值并将它们插入到 sql 表中。我的问题是当脚本读取某些日期字段时,它会将它们设置为默认值:1970-01-01 01:00:00 我注意到当遇到“天”大于 1
我有 2 台服务器。他们都使用相同的操作系统:Ubuntu 14.04 服务器 + php-fpm。我不能让它们生成相同的 strtotime结果。 日期时间:2013-12-30 18:29:59第
我使用 ths 方法来查找两个时间戳之间的差异并获取这两个时间之间的秒数,然后像计数器一样用 jquery 刷新信息。 $diff = strtotime(date('Y-m-d H:i:s')) -
我正在构建一个日记,其中包含每周 View ,我认为我已经破解了,因为日期似乎是正确的。直到我的 MySQL 查询不断返回看似随机的结果,我才意识到这个月实际上被视为一天。 $week_number
date('m/d/Y', strtotime('-1.5 years')) 返回今天(2012 年 6 月 18 日),06/18/2017。 这是为什么,有没有办法让 strtotime 处理小数
有没有办法转换strtotime与 NSDate 类似的字符串(例如:给定日期的“-3 天”)? 最佳答案 参见 NSDate 的 +dateWithNaturalLanguageString: 。我
我遇到了一个奇怪的问题。当我执行 strtotime 时,它不会考虑原始日期的小时部分,并且它总是在午夜返回。我尝试进行研究,但找不到任何具体内容。 我有什么遗漏吗? $original_date
我有一些 php 可以更改从数据库检索的时间格式: $selectedDate = $_GET['date']; $formatedDate = date("Y-d-m",strtotime($sel
我愿意 strtotime("2008-09-04") 其中 09 是月份,04 是日期,我得到的结果是: 1220500800 2008 年 9 月 4 日星期四 04:00:00 GMT。这 4
我正在使用 strtotime($my_time); 创建我在 php 数学中使用的时间戳。 变量$my_time 是从数据库中提取的HH:mm:ss 24h 格式。 我正在设置时间,但我不知道生产日
任何人都可以向我解释这个例子中的 strtotime 函数有什么问题?我正在尝试计算日期之间的差异。 PHP 5.6.0 (cli)(内置:2014 年 8 月 28 日 08:03:51)当我执行这
我正在根据用户输入的日期、月份和年份值构建时间戳。 假设用户输入了一些错误的值并且日期是不存在的“31-02-2012”,那么我必须得到一个错误的返回。但这里将其转换为附近的另一个日期。精确到:“02
这个问题在这里已经有了答案: php strtotime() messes with date of a different year (1 个回答) 关闭 9 年前。 我正在尝试使用 pickad
我有一些 php 可以更改从数据库检索的时间格式: $selectedDate = $_GET['date']; $formatedDate = date("Y-d-m",strtotime($sel
我愿意 strtotime("2008-09-04") 其中 09 是月份,04 是日期,我得到的结果是: 1220500800 2008 年 9 月 4 日星期四 04:00:00 GMT。这 4
我正在尝试使用 strtotime 转换以下日期: 07/09/2009 17:01:27 这是 9 月 7 日的欧洲/伦敦时区格式 该功能正在反转月份和日期,有什么解决方法吗? 谢谢 最佳答案 更改
我有一个循环,其中日期以不同的格式出现,例如对于某些值,它会像 '10-13-2013 04:31' ,对于某些值,它会像 >'2013-10-14T22:14:40-0700'。我尝试将其存储在数据
嗨,我有一个查询,它从数据库中选择 `timestamp` >= '".$monS."' AND `timestamp` < '".$sunE."' 以下是 $monS 和 $sunE 的定义方式:
我是一名优秀的程序员,十分优秀!