Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4

    Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4

    June 14, 2024

    Creating a DateTime from a Unix timestamp will be more convenient in PHP 8.4 with the new createFromTimestamp() method. It will support both a typical Unix timestamp as well as timestamps containing microseconds:

    $dt = DateTimeImmutable::createFromTimestamp(1718337072);
    $dt->format(‘Y-m-d’); // 2024-06-14

    $dt = DateTimeImmutable::createFromTimestamp(1718337072.432);
    $dt->format(‘Y-m-d h:i:s.u’); // 2024-06-14 03:51:12.432000

    With PHP 8.3 and below, you need to use the createFromFormat() method to convert a timestamp into a DateTime or DateTimeImmutable instance. As you can see below, it’s not too complicated, but it’ll be nice to have a new method to take care of both cases below:

    $dt = DateTimeImmutable::createFromFormat(‘U’, (string) 1718337072);
    // DateTimeImmutable @1718337072 {#7948
    // date: 2024-06-14 03:51:12.0 +00:00,
    // }

    $dt = DateTimeImmutable::createFromFormat(‘U.u’, (string) 1718337072.432);
    // DateTimeImmutable @1718337072 {#7950
    // date: 2024-06-14 03:51:12.432 +00:00,
    // }

    For those using the Carbon PHP library, it already has a createFromTimestamp() method available! It is encouraging that PHP is getting this new method at the language level as well!

    CarbonCarbon::createFromTimestamp(1718337072.432);
    // CarbonCarbon @1718337072 {#7981
    // date: 2024-06-14 03:51:12.432 UTC (+00:00),
    // }

    CarbonCarbonImmutable::createFromTimestamp(1718337072);
    // CarbonCarbonImmutable @1718337072 {#7999
    // date: 2024-06-14 03:51:12.0 UTC (+00:00),
    // }

    The post Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4 appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Master Vue Router in Vue.js 3 with Composition API
    Next Article B2B Commerce Strategy: 5 Ways Product Owner Drives Success

    Related Posts

    Machine Learning

    Salesforce AI Releases BLIP3-o: A Fully Open-Source Unified Multimodal Model Built with CLIP Embeddings and Flow Matching for Image Understanding and Generation

    May 16, 2025
    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    API Documentation: The Importance of Clear and Concise API Documentation

    Development

    Unveiling the SLUBStick Cross-Cache Attack on the Linux Kernel

    Development

    Google AI Released the Imagen 3 Technical Paper: Showcasing In-Depth Details

    Development

    The Freelancer Economy: Exploring Its Rapid Growth and Impact

    Development

    Highlights

    VESDA by Xtralis Smoke Detection Solutions Supplier in India

    May 13, 2025

    Post Content Source: Read More 

    Unveiling the Future: Srinidhi Ranganathan’s Vision of India’s AI Tech-Style Theme Park Comes to Life

    May 8, 2024

    Collective #860

    August 30, 2024

    CVE-2025-2907 – WordPress Order Delivery Date Plugin Authentication Bypass and CSRF Vulnerability

    April 26, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.