javascript - 将在 ajax 调用中工作的 Strtotime 函数
问题描述
我正在尝试使用 php 中的 strtotime 连接来自多个选择框的日期和时间值,但是,我需要在我的 ajax 调用中使用这个转换后的时间戳变量。
编码:
<form>
<select id="month">
<option value="1">January</option>
</select>
<select id="day">
<option value="22">22</option>
</select>
<select id="year">
<option value="2020">2020</option>
</select>
<select id="time">
<option value="12:00:00">12:00</option>
</select>
<button id="submitNow">
</form>
$("#submitNow").click(function(e){
e.preventDefault();
var timestamp = /*need to basically do strtotime($month . "-" . $day . "-" . $year . " " . $time) */
var promises = [];
var promise;
$.when.apply($, promises).then(function() {
$.ajax({
type:'POST',
url:'url/test',
data:{timestamp:timestamp},
_token: '{{ csrf_token() }}',
success:function(data){
window.location.href = "/library";
}
});
});
});
所以基本上,在 PHP 中,我可以转储strtotime($month . "-" . $day . "-" . $year . " " . $time)
并获取 1-22-2020 12:00:00 的 unix 时间戳,但我需要以某种方式(在 laravel 中)这样做,以便我可以在我的 ajax 中提交时间戳(1548158400)称呼
我能做到这一点的最好方法是什么?
解决方案
Blade 仍然只是一个 php 文件(name.blade.php),所以你应该能够做到这一点。
var timestamp = <?php echo strtotime($month . "-" . $day . "-" . $year . " " . $time); ?>
推荐阅读
- snowflake-cloud-data-platform - 将自定义角色分配给 SYSADMIN 有什么意义
- javascript - 反应导航 - 用作导航的道具值 setOption:参数键
- single-sign-on - Databricks SSO 身份验证失败 | 谷歌 IdP
- c# - 安装程序中的升级按钮
- java - 使用嵌套的 for 循环创建空心形状 (Java)
- python - Python中相同符号练习的邻居 - 需要帮助
- r.net - 安装 tidyverse 和 ggplot2 软件包时出错
- javascript - 使用 Node JS 在 PostgreSQL 中更新 TimeStamp 列的正确语法是什么?
- azure - AKS 节点预配失败
- python - 如何在 Colab 中使用 Plotly 在交互式 3D 图中显示图形?