Filter Request | Local Time

[ad_1]

Hello @generosus,

Thank you for using our plugin. You can always use your own code snippet, but it might be difficult to achieve other functionalities of the plugin in such cases, if they are needed.

Here is a sample snippet for shortcode in your special case(s):

add_shortcode('wpdts_snippet_date_time', 'wpdts_custom_fnc');
function wpdts_custom_fnc($atts, $content, $tag) {
    $atts_default = [
        'tag'       => 'span',  // The default result tag attribute.
        'format'    => 'G:m A', // The default result tag attribute.
    ];
    $timestamp = current_time('timestamp'); // The current UNIX timestamp according to the time zone.
    // Get the shortcode attributes.
    $atts = shortcode_atts( 
            $atts_default,
            $atts,
            $tag
    );
    $custom_date_time = date_i18n($atts['format'], $timestamp, false);     // The internationalized date and/or time value for the symbols.
    $result="";                                                           // The result string, which may ot may not be resturned as an HTML tag content.
    if ($atts['tag']) {
        $result .= "<{$atts['tag']} class=\"wpdts-snippet-date-time\">";
    }
    $result .= $custom_date_time;
    if ($atts['tag']) {
        $result .= "</{$atts['tag']}>";
    }
    return $result;
}

You can use the new shortcode like this:

[wpdts_snippet_date_time format="G:m A"]
[wpdts_snippet_date_time tag="" format="G:m A"]
[wpdts_snippet_date_time tag="p" format="Y-m-d H:i:s"]

You just need to change the tag (for HTML tag, if needed; the default is <span>) and the format attributes (using the symbols for the date_i18n function).

PS: Surely you can also use the WP Date and Time Shortcode plugin with:

[wpdts-custom format="G:i A"]

Wow! Thanks for the quick reply.

Unfortunately, the Local Server Time displayed using your code snippet is not accurate.

Details: https://prnt.sc/iqM7omYYXwq2

Can you revisit it once again, and advise?

Also, is their a way to modify your code snippet to capture the local time of our website visitor(s)?

Thank you!

Hello again,

The result does not depend on your server time and server time zone but on your WordPress General Settings time zone. There is no feature in the plugin to capture the visitor’s time. It is planned for the Pro edition but its release date is not fixed.

The only time which is used for now is the WordPress General Settings time according to the time zone or the time in the time zone set via the time_zone attribute according to:
https://www.php.net/manual/en/timezones.php

Like this:

[wpdts-date-time time_zone="Europe/Paris"]

Thank you! We look forward to your Pro Version incorporating the above.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer