简体   繁体   English

PHP-如何更改所有现有PHP文件中的日期格式

[英]PHP - How can I change the date format in all existing PHP files

I have a lot of PHP files in which I have used date() function in all files to format the date. 我有很多PHP文件,其中所有文件中都使用date()函数来格式化日期。

Currently I am using the format as MM-DD-YYYY . 目前,我使用的格式为MM-DD-YYYY Now I need to change the date format to another as DD-MM-YYYY . 现在,我需要将日期格式更改为DD-MM-YYYY

Is there any way I could change the date format in all files in a feasible way? 有什么办法可以以可行的方式更改所有文件中的日期格式?

I know I could have used a common function for formatting, but its too late :( 我知道我本可以使用通用函数进行格式化,但为时已晚:(

Thank You 谢谢

EDIT 编辑

Example of using date() function in my PHP files 在我的PHP文件中使用date()函数的示例

Currently I am using as below, 目前我正在使用如下

date('m-d-Y', strtotime(myDateStr));

But I need to change in all files as, 但我需要更改所有文件,

date('d-m-Y', strtotime(myDateStr));

Please suggest if there is any other possible way to do this. 请建议是否还有其他可能的方法。

Are you simply looking to go through the code of each of your php files and change the string 'mdY' to 'dm-Y'? 您是否只是想浏览每个PHP文件的代码并将字符串'mdY'更改为'dm-Y'?

If so, you simply need to see if your IDE/text editor has a find and replace tool. 如果是这样,您只需要查看您的IDE /文本编辑器是否具有查找和替换工具。

In Notepad and Netbeans (at least) this is Ctrl+H. 在记事本和Netbeans中(至少),这是Ctrl + H。 Then put 'mdY' in the find box and 'dmY' in the replace box, then click 'Replace All'. 然后在查找框中输入“ mdY”,在替换框中输入“ dmY”,然后单击“全部替换”。 Do this for every relevant sheet. 对每个相关工作表执行此操作。

If you already don't have one, get an editor like Atom or Notepad++ . 如果您还没有,请使用AtomNotepad ++之类的编辑器。

In Atom : 在Atom中

Press Ctrl + Shift + F to open the Find in Project - view. Ctrl + Shift + F打开在项目中查找 -视图。

To the upper Find in project textbox, type date('MM-DD-YYYY', and to the lower Replace in project textbox add date('DD-MM-YYYY', . 在上方的“在项目中查找”文本框中,键入date('MM-DD-YYYY',在下方的“ 在项目中替换”文本框中,添加date('DD-MM-YYYY',

Click the Replace All - button. 单击Replace All -按钮。


In Notepad++ : 在记事本++中

Almost similar, press Ctrl + Shift + F to open the Find in files - dialog. 几乎类似,按Ctrl + Shift + F打开“ 在文件中查找 -对话框”。 Set Find what to date('MM-DD-YYYY', and Replace with to date('DD-MM-YYYY', . Finally click Replace in Files . 设置Find what date('MM-DD-YYYY',date('MM-DD-YYYY',然后Replace withdate('DD-MM-YYYY', 。最后点击Replace in Files


Note! 注意! You might need to adjust the Directory to suit your needs. 您可能需要调整Directory以适合您的需求。


There are other editors as well capable of doing this and the process is almost identical in every one of them. 还有其他一些编辑器也可以执行此操作,并且每个编辑器的过程几乎相同。 Explore them to find how to do it in the editor in question. 探索他们以找到有关问题的编辑器。

尝试像这样更改日期格式

$date = date('d-m-Y', strtotime(datestring));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM