Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
937 views
in Technique[技术] by (71.8m points)

datetime - Add text between date and time - PHP

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

<?php
echo date();
?>


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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Derived from your example which you provided a bit late

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

be sure to use the exact syntax given! Using double quotes " instead of single ones ' will result in you getting a tab for , 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';

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 \.

If it's a datetime object

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

if you already have it as a string

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...