Frage

An iCalender file expects the DTSTART and DTEND parameters in its file to be of the format:

20140715T035959Z

Basically, long form year, double digit month, double digit day, the letter 'T' to break the date from the time, then double digit hour, minute, second, etc. appended with the letter 'Z'.

I currently have a date in the following PHP format:

Y-m-d H:i:s

I'm currently trying to format it with the DateTime::format method into an iCalender accepted string, and I thought this might work:

format('Ymd\THis\Z');

I've escaped the characters T and Z in the hopes they would appear, but when my event is echoed into the file, it's simply empty. I have a feeling my representation of the iCal datetime format is incorrect. Ideas?

Current iCal code:

DTSTART:".$calData->eventStart()."

Current $calData->eventStart() code:

public function eventStart() {
    $inputDateTime = $this->details['date_time'];

    // Convert MySQL datetime to ical datetime
    $temp = DateTime::createFromFormat('Y-m-d H:i:s', $inputDateTime);
    $eventStart = $temp->format('Ymd\THis\Z');

    echo $eventStart; // This should be RETURN, not ECHO! 
}

ANSWER:

Yeah, so it turns out this was a non-question. I was simply echoing the datetime instead of returning it.

War es hilfreich?

Lösung

You could try something like this...

<?php
$pubDt='20140715T035959Z';
$pubDt=str_replace(array('T','Z'),array('',''),$pubDt);   
$format = 'Ymdhis';
$date = DateTime::createFromFormat($format, $pubDt);
echo $newPubdate = $date->format('Y-m-d H:i:s');  //"prints" 2014-07-15 03:59:59
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top