Web Shakehands
Web Shakehands


Use current_time () when dealing with WordPress dates!

I think that many people often handle dates and times while creating plugins.
However, if you use PHP date or time , the time will be off.

So I recommend a WordPress function current_time().

You can use another function date_i18n () for WordPress, but from WordPress 3.9 or more, I suggest using current_time () .

Below is the WordPress Codex page.
Function reference / current time

The WordPress time zone is set to UTC . If this is used, the time will be off.

current_time ($ type, $ gmt = 0)

The argument $ type is timestamp or mysql ".
Or you can include 日付書式文字列 .

In the case mysql , the result is returned in date-time string format .
In the case timestamp , it can be used instead of time .

If you want to get the WordPress blog local time, it will be
current_time ('timestamp')

When returning UTC time using the second argument, it will be
current_time ('timestamp', true)

In other words, to keep the time on WordPress
Use current_time ('timestamp') .

Example: To get the current date and time

Example: Get yesterday's date using date, strototime

This article is also useful for date, strototime, timestamp in normal PHP.


This article title

Use current_time () when dealing with WordPress dates!

WordPress Plugin creation Article !

2019-07-25 Get information from the WordPress database using wpdb->prepare [plugin production] NEW!

2019-07-23 How to pass array to the database by using "update_option". WordPress Plugin Creation

2019-07-17 How to create a database table from a WordPress plugin

2019-07-13 Use current_time () when dealing with WordPress dates!

See all the articles list

Just enter your E-mail and you will receive free
mail magazine about how to make your website etc.

Go to top