I have a date I need to replicate in PHP. I just want to know if there is some sort of shortcode for it.
2013-05-09T15:23:59.802Z
It is ISO 8601. In PHP you would make it using:
echo date('c'); // as of PHP 5
See date()
This one liner achieves what you are asking.
echo date_format(date_create("#".$unix_timestamp, timezone_open('UTC')), 'Y-m-d\TH:i:s.000\Z');
Output:
2013-05-09T15:23:59.000Z
Related
I’d like to add a text line saying that “The latest event has been ended 3 days ago”
And the part “3 days ago” will automatically change as the day goes by, e.g. 1 month ago and so on…. Is there any shortcode plugin I can use for this? Or any method?
I found this plugin https://wordpress.org/plugins/the-time-ago/ but it seems to work with post/page/comment time. Not for a text line.
Best.
If you want to use a custom timestamp for the event and know how to write basic php code, you can use the php's DateTime::diff method or better, use Carbon to get the difference between your custom timestamp and today's date.
Examples in the linked docs should suffice in understanding and to echo the difference between the dates. Now, use that inside WordPress, write that code in a function in your theme's functions.php file and return the value to create a shortcode for the difference.
function eventdiff_func( $atts ) {
// write code which calculates the difference here and store it in $diff
return $diff;
}
add_shortcode( 'event_diff', 'eventdiff_func' );
Now you can use the [event_diff] shortcode whereever you'd like to output the difference that you calculated.
You can use human_time_diff function for the difference is returned in a human readable format. you can read more about human_time_diff click here.
My jSon date format:
release_date: "1426153440",
When I use like this, its done but has a format problem:
{$info.release_date}
Generate to:
1426153440
How can I solve format problem in tpl files? Thank you.
You can use date_format, with it you can combine the conversion specifiers available in strftime().
Example:
{$info.release_date|date_format:"%Y-%m-%d"}
I've got a JSON variable ($epoch) which contains the date in epoch (1370777177), and I'd like to convert it to the following format and output it:
date "+%F %R" -ud #1370777177
which returns:
2013-06-09 11:26
So I figure using php to echo the command is one way to do it. Is there a way to convert the epoch to the format above and append it to a DIV using JS? That might be a lot easier. I've tried creating a PHP variable which encodes the JSON var:
$date = json_encode($epoch);
echo exec ('date "+%F %R" -ud #%date');
But that doesn't work.
echo json_encode($epoch)
returns 'null'. The JSON variable is in a external .js file.
Is there a way to convert the epoch to the format above and append it to a DIV using JS?
Yes, there is.
Also exec() will scale awesomely.
I'm using wordpress. I remember messing with the code of <?php the_time('d.m.y') ?> and getting something like "2011161457" (2011 16-1 4:57) I don't remember how I did it. I want just the numbers anyone knows how to do it?
Look at the PHP date() man page. Wordpress's time_time() is basically just a wrapper around that and uses the exact same formating options.
I have date in this format: 2010-01-11. I want to display JAN-11. How can i do this using php?
<?php echo date("M-y",strtotime("2010-01-11"));?>
Rudu's answer is correct, +1.
"M-y" would result to "Jan-11"
so if you need the output to be UPPERCASE, dont forget to use strtoupper().
<?php echo strtoupper(date("M-y",strtotime("2010-01-11")));?>
also bookmark this for later reference.
http://www.php.net/manual/en/function.date.php
Cheers