本地化 strtotime 字符串的输出

发布于 2024-12-07 03:15:00 字数 295 浏览 1 评论 0原文

我阅读了有关 strtotime 和 strftime 以及相关函数的手册,但在尝试解决我的问题方面似乎无法取得任何进展。

基本上,我对以本地语言(在本例中为荷兰语)打印 $deldate5 输出的方法感兴趣。

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

我很可能需要放弃 strtotime 字符串并将其替换为其他内容,以便于使用“今天 + 5 天”参数。

有人可以帮忙吗?先感谢您。

I read through manuals concerning strtotime and strftime as well as related functions, 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑脸一如从前 2024-12-14 03:15:00

让我们分开来看:

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

这做了两件事:

  1. strtotime:创建 UNIX 时间戳(自纪元以来的秒数)。
  2. 日期:格式化输出。

您的问题与输出(2.)有关,而不是创建时间戳(1.)。因此,让我们把它分开:

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

现在唯一需要的就是处理以下代码行:

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

的格式化参数dateDocs 函数是:

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

由于 l(小写 L)需要输出中的区域设置,让我们看看哪个格式化参数 strftimeDocs 必须提供这一点类似:

%A - A full textual representation of the day.

所以从date更改为strftime只是一小步:

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

希望这有帮助。

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.

风情万种。 2024-12-14 03:15:00

尝试将日期默认时区设置为您的本地时区:

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

Try setting the date default timezone to your local timezone:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文