コード例 #1
0
     * <p>
     * The output will be one of the following ISO-8601 formats:
     * <ul>
     * <li>{@code uuuu-MM-dd'T'HH:mm}</li>
     * <li>{@code uuuu-MM-dd'T'HH:mm:ss}</li>
     * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSS}</li>
     * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSS}</li>
     * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS}</li>
     * </ul>
     * The format used will be the shortest that outputs the full value of
     * the time where the omitted parts are implied to be zero.
     *
     * @return string a string representation of this date-time, not null
     */
    public function __toString()
    {
        return $this->date->__toString() . 'T' . $this->time->__toString();
    }
    public function serialize()
    {
        return $this->date->getYear() . ':' . $this->date->getMonthValue() . ':' . $this->date->getDayOfMonth() . ':' . $this->time->getHour() . ':' . $this->time->getMinute() . ':' . $this->time->getSecond() . ':' . $this->time->getNano();
    }
    public function unserialize($serialized)
    {
        $v = explode(':', $serialized);
        $this->date = LocalDate::of($v[0], $v[1], $v[2]);
        $this->time = LocalTime::of($v[3], $v[4], $v[5]);
    }
}
LocalDateTime::init();