如何获得这个小时的时间戳范围?(How to get the timestamp range of this hour?)
如何获取当前小时的UNIX时间戳范围,我的意思是第一秒的一个,最后一秒的另一个。 所以如果它是18:45我会得到18:00和18:59的时间戳。
谢谢
How to get the UNIX timestamp range of the current hour, i mean one of the first second and the other for the last second. so if it's 18:45 i would get the timestamp of 18:00 and 18:59.
Thanks
原文:https://stackoverflow.com/questions/2679828
更新时间:2019-12-17 04:14
最满意答案
您可以使用getdate()获取当前时间的组件,并使用mktime()来查找时间戳:
$date = getdate();
$start = mktime($date['hours'], 0, 0);
$end = $start + (60*60);
你也可以使用date() ,这稍微简单一些:
$start = mktime(date("H"), 0, 0);
$end = $start + (60*60);
You can get the components of the current time with getdate(), and use mktime() to find the timestamps:
$date = getdate();
$start = mktime($date['hours'], 0, 0);
$end = $start + (60*60);
You can also use date(), which is slightly simpler:
$start = mktime(date("H"), 0, 0);
$end = $start + (60*60);
2010-04-21
相关问答
t = pd.Timestamp.now()
(t - t.normalize()).total_seconds()
编辑 要获取小时内的总秒数: t = pd.Timestamp.now()
(t - t.to_period("H").start_time).total_seconds()
t = pd.Timestamp.now()
(t - t.normalize()).total_seconds()
EDIT To get the total number of seconds in
...
可能是您有一个多线程应用程序,并且对gmtime调用不是线程安全的(可重入)。 如果是这种情况,请尝试使用可重入版本: gmtime_r It could be that you have a multi-threaded application, and calls to gmtime are not thread-safe (re-entrant). If this is the case, try using the re-entrant version: gmtime_r
这是错误的: if ( (df_mean['date'].dt.hour >= 6) & (df_mean['date'].dt.hour < 20) ):
您正在将一组布尔值视为布尔值。 它不是,它是一个数组。 一次完成一步: match = df_mean['date'].dt.hour.between(6, 19)
然后你可以做这样的事情: if match.any():
if match.all():
if match.sum() > len(df) / 2:
或者你可以将原始数
...
您可以使用UNIX_TIMESTAMP()函数完成工作。 SELECT (
UNIX_TIMESTAMP(NOW()) - (MINUTE(NOW()) * 60 + SECOND(NOW()))
) AS startUnixTimestampOfCurrentHour;
说明: 假设, Now()返回2016-03-07 13:05:23 。 现在,如果你仔细观察,那么你只需要避开second和second部分。 Minute和Second预计价值zero 。
...
function checkTimeSlot($occupied, $occDuration, $checkStart, $checkDuration)
{
$isValid = true;
foreach($occupied as $key => $occStartTime)
{
$occEndTime = $occStartTime + $occDuration;
if($checkStart > $occStartTime || $ch
...
您可以使用getdate()获取当前时间的组件,并使用mktime()来查找时间戳: $date = getdate();
$start = mktime($date['hours'], 0, 0);
$end = $start + (60*60);
你也可以使用date() ,这稍微简单一些: $start = mktime(date("H"), 0, 0);
$end = $start + (60*60);
You can get the components of the current
...
我会说实话。 我不确定我是否亲近。 我从qqq中的WHERE子句中删除了大部分内容,因为它在外部查询的where子句中重复。 我也切换到ISO时间戳,因为它对我来说更容易阅读。 您可能希望将其重写为可以传递参数的函数。 WITH cal AS (
SELECT generate_series('2011-02-02 00:00:00'::timestamp ,
'2012-04-01 05:00:00'::timestamp ,
...
你可以用gmdate函数做到这gmdate echo gmdate("H:i", time());
如果你只需要几小时而不是只有gmdate在gmdate gmdate - 格式化GMT / UTC日期/时间 演示 正如@Mark Baker所建议的,如果你想修复第二个定时器,你可以手动编写 echo gmdate("H:00", time());
you can do this with gmdate function echo gmdate("H:i", time());
if you
...
所以你说你只想改变00:00到15:00之间的日期? 如果是这样,只需添加: WHERE TRUNC(CHANGE_DATE) = to_date('{RUN_DATE_YYYY-MM-DD}', 'YYYY-MM-DD') AND TO_CHAR(CHANGE_DATE,'HH24') <=15
(我假设是Oracle DB)。 So you are saying you want only change dates in the range from 00:00 to 15:00 ? If
...
您应该使用TemporalType.TIMESTAMP将字段映射到java.sql.Timestamp ,因此它还将包含与时间相关的信息,而不仅仅是日期。 相比之下,您使用的类型TemporalType.DATE映射到java.sql.Date ,类包含日,月等信息。 因此,您的代码将转换为: @Entity
public class Session implements Serializable {
..
@Temporal(TemporalType.TIMESTAMP)
p
...