开发者

Localize output of strtotime string

开发者 https://www.devze.com 2023-04-08 19:27 出处:网络
I read through manuals concerning strtotime and strftime as well as related fun开发者_如何学Goctions, but I cannot seem to make any progress in trying to solve my problem.

I read through manuals concerning strtotime and strftime as well as related fun开发者_如何学Goctions, but I cannot seem to make any progress in trying to solve my problem.

Basically, I'm interested in ways to print output of $deldate5 in local language (Dutch in this case).

$deldate5 = date("d.m.Y., l", strtotime("today + 5 day", time()));

I would most likely need to ditch strtotime string and replace it with something else in order to facilitate "today + 5 day" parameter.

Can anyone help? Thank you in advance.


Let's pick this apart:

$deldate5 = date("d.m.Y., l", strtotime("today + 5 day", time()));

This is doing two things:

  1. strtotime: Create a UNIX timestamp (number of seconds since the epoch).
  2. date: Format the output.

Your problem is related to the output (2.), not creating the timestamp (1.). So let's put this apart:

$timestamp = strtotime("today + 5 day", time());
$formatted = date("d.m.Y., l", $timestamp);

The only thing required now is to deal with the following line of code:

$formatted = date("d.m.Y., l", $timestamp);

The formatting parameters for the dateDocs function are:

d - Day of the month, 2 digits with leading zeros
m - Numeric representation of a month, with leading zeros
Y - A full numeric representation of a year, 4 digits
l - A full textual representation of the day of the week

As l (lower case L) requires a locale in your output, let's see which formatting parameter strftimeDocs has to offer that is similar:

%A - A full textual representation of the day.

So it's just a small step to change from date to strftime:

$formatted = strftime("%d.%m.%Y., %A", $timestamp);

Hope this helps.


Try setting the date default timezone to your local timezone:

http://www.php.net/manual/en/function.date-default-timezone-set.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号