There is no problem not worth solving, and no technology not worth learning!

Convert 20231020105244000+0800 to the format of Y-M-D H:I:S in PHP

基于 DateTime::createFromFormat -- date_create_from_format — 根据指定格式解析时间字符串。打印返回的 DateTime 对象。

1. The existing time field, its value is: 20231020105244000+0800, it can be known that its format in PHP is: ymdhisvo. Reference:https://www.php.net/manual/zh/datetime.format.php

2. Based on DateTime::CreateFromFormat — date_create_from_format – parse the time string according to the specified format. Print the returned DateTime object. as shown in Figure 1

基于 DateTime::createFromFormat -- date_create_from_format — 根据指定格式解析时间字符串。打印返回的 DateTime 对象。
Figure 1

print_r(DateTime::createFromFormat("YmdHisvO", '20231020105244000+0800'));




DateTime Object
(
    [date] => 2023-10-20 10:52:44.000000
    [timezone_type] => 1
    [timezone] => +08:00
)


3. Based on DateTimeInterface::Format — DateTimeImmutable::Format — DateTime::Format — Date_Format — return the formatted date according to the specified format .


echo DateTime::createFromFormat("YmdHisvO", '20231020105244000+0800')->format("Y-m-d H:i:s");



2023-10-20 10:52:44


Need long-term technical maintenance or remote troubleshooting?

I am a PHP / Go backend engineer with 15+ years of experience, focused on existing system maintenance, bug fixing, performance optimization, server troubleshooting, WordPress maintenance, and small feature iterations.

If your project is facing any of the following issues, we can start with a small troubleshooting task first:

  • ✅ PHP / Laravel / Yii2 legacy systems without active maintenance
  • ✅ Go / Gin backend APIs that need troubleshooting or optimization
  • ✅ Slow, broken, or unstable WordPress websites
  • ✅ Nginx / MySQL / Redis / Linux server issues
  • ✅ CDN / Cloudflare / DNS / HTTPS configuration problems
  • ✅ Long-term remote technical support or part-time maintenance

More details: About Me & Collaboration

WeChat: 13980074657
Email: shuijingwanwq@gmail.com
Telegram: @shuijingwan
GitHub: https://github.com/shuijingwan

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.