iso8601 포멧으로 time string 만들기 | |||
| |||
이경우 xmlrpc 모듈을 사용하는 경우 혹은 php에서 iso8601_encode, iso8601_decode 기능을 지원하는 경우는 그 함수를 그대로 사용하면 된다. 그렇지 않은 경우는 다음의 코드를 상단에 define하고 써주면 된다. // 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; } 여기서 한국은 GMT+09:00 이므로 다음과 같은 형태로 사용한다. $iso8601_current_time = iso8601_encode( time(), 9); 이를 응용하면 ime Format을 편하게 사용 할 수 있다. Tags: conversion iso8601 iso8601_decode iso8601_encode time format 변환 | |||
| |||
| |||
로그인을 하시면 댓글을 등록 할 수 있습니다. |
SIMILAR POSTS 배열(array)을 문자열(string)으로 만들어주는 친절한 함수 |
OTHER POSTS IN THE SAME CATEGORY 실시간 동영상을 끊김없이 감상하기 |