在日期和时间之间添加文本-PHP [英] Add text between date and time - PHP

查看:88
本文介绍了在日期和时间之间添加文本-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在PHP中的日期和时间之间添加文本?

Is it possible to add text between date and time in PHP ?

<?php
echo date();
?>


这将创建 (07-06-2014 00:00)
但是我想要(2014年7月6日00:00).


This will create (07-06-2014 00:00)
But i want (07-06-2014 at 00:00 hours).

推荐答案

源自您的示例,您提供的时间有点晚

Derived from your example which you provided a bit late

echo date('d-m-Y \a\t H:i:s') . ' hours';

请务必使用给出的确切语法!使用双引号"而不是单引号'将导致您获得\t的标签,那么您将需要使用\\a\\t以获得正确的语法,如下例所示:

be sure to use the exact syntax given! Using double quotes " instead of single ones ' will result in you getting a tab for \t, you'd than need to use \\a\\t for proper syntax as in the example below:

echo date("d-m-Y \\a\\t H:i:s") . ' hours';

这是由于php引用是如何工作的,并且与日期格式无关,'中的内容不会被转义,而"中的内容则会转义,因此,如果您使用",请务必使用double反斜杠\\.

This is due to how php quoting works and has nothing to do with date formatting, things in ' don't get escaped while those in " do, so if you use " be sure to use double backslashes \\.

如果它是日期时间对象

echo $datetime->format('d-m-Y \a\t H:i:s') . ' hours';

如果您已经将其作为字符串

if you already have it as a string

echo str_replace(' ', ' at ', $datetime) . ' hours';

这篇关于在日期和时间之间添加文本-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆