PHP

ISO 8601 format time format string conversion

CK CK 3788 
Created at
Updated at  
534 0 0

When communicating with XML, ISO 8601 format time string is used. In case of using xmlrpc, it contains ISO 8601 format time string conversion module such as iso8601_encode, and iso8601_decode.

If you don't use xmlrpc module, you can declare below module in order to use ISO 8601 format time string conversion module. Of course, if your PHP supports the function, you don't need to declare  below functions.
 

// date helpers
function iso8601_encode($timet, $utc=0) {
    // return an ISO8601 encoded string
    // really, timezones ought to be supported
    // but the XML-RPC spec says:
    //
    // "Don't assume a timezone. It should be specified by the server in its
  // documentation what assumptions it makes about timezones."
    // 
    // these routines always assume localtime unless 
    // $utc is set to 1, in which case UTC is assumed
    // and an adjustment for locale is made when encoding
    if (!$utc) {
        $t=strftime("%Y%m%dT%H:%M:%S", $timet);
    } else {
        if (function_exists("gmstrftime")) 
            // gmstrftime doesn't exist in some versions
            // of PHP
            $t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
        else {
            $t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z"));
        }
    }
    return $t;
}

function iso8601_decode($idate, $utc=0) {
    // return a timet in the localtime, or UTC
    $t=0;
    if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",
                     $idate, $regs)) {
        if ($utc) {
            $t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
        } else {
            $t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
        }
    } 
    return $t;
}



As I mentioned, above functions will be very useful if you need to implement RSS, or Sitemap.
 

Tags FIrefox Session FireFox ISO8601_decode PHP iso8601_encode Facebook X
Comments 0
Similar posts
  1. HTML redirection in PHP
    398
  2. Get the actual filesize for a size above 2GB in Windows
    427
  3. How to convert W3C Date Time Format ?
    453
  4. How to download a file from a certain URL to server ?
    419
  5. How to extract file name from given URL ?
    442
  6. File downloading via HTTP
    445
  7. How to block a connection from the certain site ?
    350
  8. XMLRPC example
    760
  9. How to upload attachments such as image by metaWeblog API ?
    391
  10. How to post blog content by metaweblog API ?
    485
  11. How to put timeout when opening URL by fopen ?
    440
  12. Posting to a Wordpress Blog Via XMLRPC Using Blogger API
    763
  13. How to limit by Timeout when opening URL ?
    457
  14. foreach loop
    442
  15. Can PHP switch in strings ?
    391
  16. PHP Switch Example
    427
  17. How to send email in PHP ?
    889
  18. How to pass variables via url
    468
  19. How to declare array in PHP like C/C++
    670
  20. PHP date and time formatting
    428
  21. How to redirect browser in PHP ?
    484
  22. How to get current filename as variable ?
    768
  23. email validation, simple
    412
  24. How to ban / block IP addresses
    509
  25. for loop - simple
    449
  26. form action - detect form post
    428
  27. How to make random number ?
    517
  28. How to force cookies, disable php sessid in URL ?
    555
  29. How to check if a file exists ?
    786
  30. How to include a file with error reporting ?
    428
  1. Date format validation in PHP
    570
  2. PHP function converts new line to BR tag
    558
  3. Email Validation Snipet in PHP
    378
  4. PHP socket programming to get content with post method
    409
  5. Get Remote IP Address in PHP
    494
  6. How to remove HTML tags in text string?
    405
  7. Directory listing in PHP
    511
  8. Seconds to String in PHP
    435
  9. How to delete file on certain path ?
    388
  10. ASCII Artwork Generator from image file
    469
  11. How to limit by Timeout when opening URL ?
    457
  12. How to put timeout when opening URL by fopen ?
    440
  13. How to convert W3C Date Time Format ?
    453
  14. Get the actual filesize for a size above 2GB in Windows
    427
  15. HTML redirection in PHP
    398
  16. How to download a file from a certain URL to server ?
    419
  17. How to extract file name from given URL ?
    442
  18. File downloading via HTTP
    445
  19. XMLRPC example
    760
  20. How to upload attachments such as image by metaWeblog API ?
    391
  21. How to post blog content by metaweblog API ?
    485
  22. Posting to a Wordpress Blog Via XMLRPC Using Blogger API
    763
  23. foreach loop
    442
  24. Can PHP switch in strings ?
    391
  25. PHP Switch Example
    427
  26. How to send email in PHP ?
    889
  27. How to pass variables via url
    468
  28. How to declare array in PHP like C/C++
    670
  29. PHP date and time formatting
    428
  30. How to redirect browser in PHP ?
    484
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    27
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    24
  3. How do I create animated background for Google Meet?
    19,720
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    217
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    85
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    153
  7. Array of arguments passed to script in PHP
    85
  8. Invalid Auction Storms in Ad Tech
    93
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    198
  10. The Two Clocks of Ad Server Architecture
    63
  11. Frequency Cap Architecture Overview
    509
  12. Collecting Proof-of-Play from 100,000 Screens
    141
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    280
  14. What is RedisVL?
    105
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    224
  16. TPU & GPU Cluster Management Tools
    232
  17. The Concept of Scaffolding in AI Agents
    221
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    576
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    253
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    328
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    197
  22. Machine Learning: Training vs. Ranking
    213
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    217
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    189
  25. Designing a Data Curation System Around a Vector Database
    215
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    649
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    185
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    207
  30. Understanding Data Lineage
    252