我正在尝试将字符串转换11/24/2011 @ 01:15pm为 UNIX 时间戳。格式为m-d-Y @ h:ia
我似乎无法开始strtotime使用字符串。有没有办法反转数据功能?我唯一的选择是创建一个新的非默认 php 函数来转换字符串吗?
服务器运行 CentOS 5、Apache 2.2 和 PHP 5.2.17。
我有一个“即将发生的事件”页面和一个“过去的事件”页面。每个事件都有一个名为“event_date”的自定义字段。
我想创建一个循环来显示所有比今天更大的事件。我已经浏览了这些文章,但无法让它工作:http : //support.advancedcustomfields.com/forums/topic/how-do-i-filter-and-sort-event-posts-with -开始和结束日期/
https://wordpress.org/support/topic/plugin-advanced-custom-fields-sorting-by-date-picker
根据我在上面三个链接中收集的内容,我会将其放在我的 functions.php 文件中:
// CREATE UNIX TIME STAMP FROM DATE PICKER
function custom_unixtimesamp ( $post_id ) {
if ( get_post_type( $post_id ) == 'event_type' ) {
$event_date = get_post_meta($post_id, 'event_date', true);
if($event_date) {
$dateparts = explode('/', $event_date);
$newdate1 = strtotime(date('d.m.Y H:i:s', strtotime($dateparts[1].'/'.$dateparts[0].'/'.$dateparts[2])));
update_post_meta($post_id, 'unixstartdate', $newdate1 );
}
}
}
add_action( 'save_post', 'custom_unixtimesamp', 100, 2);
Run Code Online (Sandbox Code Playgroud)
然后我会在我的页面模板中添加这样的内容:
<?php
$today = time();
$args = array(
'post_type' => 'event_type',
'posts_per_page' => 5,
'meta_query' => array( …Run Code Online (Sandbox Code Playgroud) php wordpress datepicker unix-timestamp advanced-custom-fields
在发布此内容之前,我已经在 stackoverflow 中提到了这些问题。就我而言,我需要将 1426023505154 转换为日期格式。为了确保时间戳有效,我检查了http://www.epochconverter.com。我用这些代码进行转换。但这不起作用:
date_default_timezone_set('Asia/Calcutta');
$date = new DateTime();
$date->setTimestamp(1426023505154);
echo $date->format('U = Y-m-d H:i:s') ;
echo gmdate("Y-m-d\TH:i:s\Z", 1426023505154);
echo echo date('d-m-Y', 1426023505154);
Run Code Online (Sandbox Code Playgroud)
但所有这些都会导致错误的结果,例如:
47158-11-20 21:49:14
20-11-47158
请让我知道如何解决这个问题。谢谢
如果您在内存中拥有每个整数来构造 datetime 对象,是否有比以下更好的方法。
atoi(datetime(year,month,day,hour,minute,second).stftime("%s"))
Run Code Online (Sandbox Code Playgroud) php中strtotime()方法返回的时间戳大小是多少?我猜可能是32位的。有没有办法从 php 中的 strtotime('now') 获取 64 位时间戳?
如果我在世界任何地方(宇宙上)的任何系统、编程语言中同时请求一些 Unix 时间戳,它们会总是相同吗?或者价值观有可能不同吗?
作为先决条件,我假设每个系统都必须正确配置其时间。附加问题:现在,我可以假设具有互联网连接的设备有正确的时间吗?
那么,Unix时间戳的使用有多可靠呢?例如,如果我想在某个时间为世界上的不同用户设置警报,并且我只广播时间戳,我可以假设警报在同一秒内发生吗?
(我想,这里应该忽略光速旅行。)
在 firebase 云函数中,我正在使用打字稿,但无法获得将 firestore 时间戳转换为人类可读格式的解决方案,目前它显示为“063720731421.495000000”如何解决这个问题?
timestamp unix-timestamp node.js google-cloud-functions google-cloud-firestore
我从服务器获取时间字符串,但是当我将其转换为本地时间时,它给出的值不正确
年如52635
我的代码是-
if let dateVal = (model.insert_date){
if dateVal != ""{
//dateVal = "1598859638000"
let dt = Double(dateVal)
let date = Date(timeIntervalSince1970:dt!)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "E MMM d yyyy"
//dateFormatter.locale = Locale.init(identifier: "en")
let outputDate = dateFormatter.string(from: date)
print(outputDate) //Fri Nov 6 52635
cell.lblName.text = outputDate
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用类型为 的输入datetime-local。我需要将其转换为 unix 时间戳。
以下是提交的原始值的格式示例2018-06-12T19:30。
我需要将上述格式的日期转换为1608954764当前的 unix 时间戳格式。
我希望在7天或更早的时候删除数据库中的记录.我的服务器时间设置为英国时间,但出于某种原因,我在下面写的代码总是回显的帐户被删除为7天或更长时间,由于某种原因,它不起作用.在我测试我的测试数据库之前,我决定现在使用一个简单的回声,但正如我所说它不会起作用.
任何人有任何建议,为什么它不工作?我一定做错了什么.
<?php
// Get Current Time
$current_time = time();
/* The time i used below (unix) for testing is
18-02-2011 14:34:24 (yesterdays date/time) */
$account_delete = strtotime(time('1298039664'));
if ($current_time - $account_delete >= (7*24*60*60)){
echo 'Account Deleted as 7 or more days old';
} else {
echo 'Account Not Deleted as less than 7 days old';
}
?>
Run Code Online (Sandbox Code Playgroud)