本文整理汇总了PHP中strptime函数的典型用法代码示例。如果您正苦于以下问题:PHP strptime函数的具体用法?PHP strptime怎么用?PHP strptime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strptime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: pleac_Parsing_Dates_and_Times_from_Strings
function pleac_Parsing_Dates_and_Times_from_Strings()
{
// 'strtotime' parses a textual date expression by attempting a 'best guess' at
// the format, and either fails, or generates a timestamp. Timestamp could be fed
// into any one of the various functions; example:
$timestamp = strtotime('1998-06-03');
echo strftime('%Y-%m-%d', $timestamp) . "\n";
// 'strptime' parses a textual date expression according to a specified format,
// and returns an array of date components; components can be easily dumped
print_r(strptime('1998-06-03', '%Y-%m-%d'));
// ----------------------------
// Parse date string according to format
$darr = strptime('1998-06-03', '%Y-%m-%d');
if (!empty($darr)) {
// Show date components in 'debug' form
print_r($darr);
// Check whether there was a parse error i.e. one or more components could not
// be extracted from the string
if (empty($darr['unparsed'])) {
// Properly parsed date, so validate required components using, 'checkdate'
if (checkdate($darr['tm_mon'] + 1, $darr['tm_mday'], $darr['tm_year'] + 1900)) {
echo "Parsed date verified as correct\n";
} else {
echo "Parsed date failed verification\n";
}
} else {
echo "Date string parse not complete; failed components: {$darr['unparsed']}\n";
}
} else {
echo "Date string could not be parsed\n";
}
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:32,代码来源:Parsing_Dates_and_Times_from_Strings.php
示例2: getWeekday
public static function getWeekday($date)
{
$d = strptime($date, '%Y-%m-%d');
$timestamp = mktime(0, 0, 0, $d['tm_mon'] + 1, $d['tm_mday'] + $i, $d['tm_year'] + 1900);
switch ((int) date("w", $timestamp)) {
case 0:
$day = "неделя";
break;
case 1:
$day = "понеделник";
break;
case 2:
$day = "вторник";
break;
case 3:
$day = "сряда";
break;
case 4:
$day = "четвъртък";
break;
case 5:
$day = "петък";
break;
case 6:
$day = "събота";
break;
default:
brak;
}
return $day;
}
开发者ID:raxbg,项目名称:Jedi-Framework,代码行数:31,代码来源:dates.php
示例3: testStrPTime
public function testStrPTime()
{
$date = strptime('01/01/1970', "%d/%m/%Y");
$this->assertEquals(1, $date['tm_mday']);
$this->assertEquals(0, $date['tm_mon']);
$this->assertEquals(70, $date['tm_year']);
}
开发者ID:pixlr,项目名称:ZCE-2,代码行数:7,代码来源:DateTest.php
示例4: wpp_date_to_unix
function wpp_date_to_unix($date)
{
$date_slash = str_replace("/", "-", $date);
$date_format = strptime($date_slash, '%m-%d-%Y');
$timestamp = mktime(0, 0, 0, $date_format['tm_mon'] + 1, $date_format['tm_mday'], $date_format['tm_year'] + 1900);
return $timestamp;
}
开发者ID:saowapan,项目名称:wp-promotions,代码行数:7,代码来源:util.php
示例5: validateParams
/**
* Required parameter check
* @param $params params extracted from the POST
*/
protected function validateParams($params)
{
$required = array('eventid', 'startdate', 'enddate', 'increment', 'userdefs');
foreach ($required as $arg) {
if (!isset($params[$arg])) {
$this->dieUsageMsg(array('missingparam', $arg));
}
}
// check if event id parses to an int greater than zero
if ((int) $params['eventid'] < 0) {
$this->dieUsage('Invalid event ID', 'badeventid');
}
// check start and end date are of proper format
if ($params['startdate'] != 0 && strptime(SpecialClickTracking::space_out_date($params['startdate']), "%Y %m %d") === false) {
$this->dieUsage("startdate not in YYYYMMDD format: <<{$params['startdate']}>>", 'badstartdate');
}
if ($params['enddate'] != 0 && strptime(SpecialClickTracking::space_out_date($params['enddate']), "%Y %m %d") === false) {
$this->dieUsage("enddate not in YYYYMMDD format: <<{$params['enddate']}>>", 'badenddate');
}
// check if increment is a positive int
if ((int) $params['increment'] <= 0) {
$this->dieUsage('Invalid increment', 'badincrement');
}
if (json_decode($params['userdefs']) == null) {
$this->dieUsage("Invalid JSON encoding <<{$params['userdefs']}>>", 'badjson');
}
}
开发者ID:BackupTheBerlios,项目名称:swahili-dict,代码行数:31,代码来源:ApiSpecialClickTracking.php
示例6: parse
/**
* Parses single line of http log into array structure
*
* @param string
* @return array
*/
public static function parse($line)
{
// Coarse match
if (!preg_match('/^([^ ]+) ([^ ]+) ([^ ]+) \\[([^ ]+) ([^\\]]+)] "([^"]+)" ([0-9]+) ((?:[0-9]+)|-) "([^"]+)" "([^"]+)"$/', $line, $matches)) {
throw new A2o_Parser_Log_Http_Exception("Unable to parse line: \n{$line}\n");
}
$res = array('host' => $matches[1], 'user' => $matches[3], 'date_time' => $matches[4], 'time_zone' => $matches[5], 'request_line' => $matches[6], 'http_status' => $matches[7], 'data_sent' => $matches[8], 'referer' => $matches[9], 'user_agent' => $matches[10]);
$dateTime = $matches[4];
$timeZone = $matches[5];
$requestLine = $matches[6];
// Get unix timestamp
$dateTimeArray = strptime("{$dateTime} {$timeZone}", '%d/%b/%Y:%H:%M:%S %z');
if ($dateTimeArray === FALSE) {
throw new A2o_Parser_Log_Http_Exception("Unable to parse datetime line: \n{$dateTime}\n");
}
$timestamp = mktime($dateTimeArray['tm_hour'], $dateTimeArray['tm_min'], $dateTimeArray['tm_sec'], $dateTimeArray['tm_mon'] + 1, $dateTimeArray['tm_mday'], $dateTimeArray['tm_year'] + 1900);
$res['timestamp'] = $timestamp;
// Parse the request line
if (!preg_match('/^([A-Z]+) ([^ ]+) (HTTP\\/1.[01])\\s*$/', $requestLine, $matches)) {
echo "{$line}\n";
throw new A2o_Parser_Log_Http_Exception("Unable to parse request line: \n'{$requestLine}'\n");
}
$res['request_method'] = $matches[1];
$res['request_file'] = $matches[2];
$res['http_protocol_version'] = $matches[3];
// Return to caller
return $res;
}
开发者ID:bostjan,项目名称:a2o-php-library,代码行数:34,代码来源:Line.php
示例7: clean
public function clean($value)
{
parent::clean($value);
$out = null;
foreach ($this->input_formats as $format) {
if (false !== ($date = strptime($value, $format))) {
$day = str_pad($date['tm_mday'], 2, '0', STR_PAD_LEFT);
$month = str_pad($date['tm_mon'] + 1, 2, '0', STR_PAD_LEFT);
$year = str_pad($date['tm_year'] + 1900, 4, '0', STR_PAD_LEFT);
$h = str_pad($date['tm_hour'], 2, '0', STR_PAD_LEFT);
$m = str_pad($date['tm_min'], 2, '0', STR_PAD_LEFT);
$s = $date['tm_sec'];
if ($s > 59) {
$s = 59;
}
$s = str_pad($s, 2, '0', STR_PAD_LEFT);
$out = $year . '-' . $month . '-' . $day . ' ' . $h . ':' . $m . ':' . $s;
break;
}
}
if ($out !== null) {
// We internally use GMT, so we convert it to a GMT date.
return gmdate('Y-m-d H:i:s', strtotime($out));
}
throw new Pluf_Form_Invalid(__('Enter a valid date/time.'));
}
开发者ID:chenchaodev,项目名称:vimercode,代码行数:26,代码来源:Datetime.php
示例8: parserAction
/**
* @Route("/admin/parser")
* @Method("GET")
* @Template()
*/
public function parserAction()
{
set_time_limit(0);
$rootDir = $this->get('kernel')->getRootDir();
$content = file_get_contents(realpath($rootDir . '/../docs/google-groups-posts.bkp.html'));
$crawler = new Crawler($content);
$subjectFilterPrefix = 'pergunta';
$em = $this->get('doctrine')->getManager();
$crawler->filter('body > table > tbody > tr > td > div > div > div:first-child')->each(function (Crawler $node, $i) use(&$subjectFilterPrefix, $em) {
$subject = $node->filter('a')->first();
$author = $node->filter('div:first-child > div')->attr('data-name');
$time = $node->filter('div')->last()->children()->attr('title');
setlocale(LC_ALL, NULL);
setlocale(LC_ALL, 'pt_BR');
if (substr(strtolower(utf8_decode($subject->text())), 0, strlen($subjectFilterPrefix)) == $subjectFilterPrefix) {
$timeParts = explode(',', utf8_decode($time));
$timeParsed = strptime(end($timeParts), '%d de %B de %Y %Hh%Mmin%Ss');
$createdAt = new \DateTime(date('Y-m-d h:i:s', mktime($timeParsed['tm_hour'], $timeParsed['tm_min'], $timeParsed['tm_sec'], 1, $timeParsed['tm_yday'] + 1, $timeParsed['tm_year'] + 1900)));
$entity = $em->getRepository('CekurteZCPEBundle:Parser')->findOneBy(array('subject' => utf8_decode($subject->text())));
if (!$entity instanceof Parser) {
$parser = new Parser();
$parser->setSubject(utf8_decode($subject->text()))->setUrl($subject->attr('href'))->setAuthor(utf8_decode($author))->setCreatedAt($createdAt);
$em->persist($parser);
$em->flush();
}
}
});
return array();
}
开发者ID:andrelotto,项目名称:zcpe,代码行数:34,代码来源:DefaultController.php
示例9: isValid
/**
* Returns TRUE if submitted value validates according to rule
*
* @return boolean
* @see \TYPO3\CMS\Form\Validation\ValidatorInterface::isValid()
*/
public function isValid()
{
if ($this->requestHandler->has($this->fieldName)) {
$value = $this->requestHandler->getByMethod($this->fieldName);
if (function_exists('strptime')) {
$parsedDate = strptime($value, $this->format);
$parsedDateYear = $parsedDate['tm_year'] + 1900;
$parsedDateMonth = $parsedDate['tm_mon'] + 1;
$parsedDateDay = $parsedDate['tm_mday'];
return checkdate($parsedDateMonth, $parsedDateDay, $parsedDateYear);
} else {
// %a => D : An abbreviated textual representation of the day (conversion works only for english)
// %A => l : A full textual representation of the day (conversion works only for english)
// %d => d : Day of the month, 2 digits with leading zeros
// %e => j : Day of the month, 2 digits without leading zeros
// %j => z : Day of the year, 3 digits with leading zeros
// %b => M : Abbreviated month name, based on the locale (conversion works only for english)
// %B => F : Full month name, based on the locale (conversion works only for english)
// %h => M : Abbreviated month name, based on the locale (an alias of %b) (conversion works only for english)
// %m => m : Two digit representation of the month
// %y => y : Two digit representation of the year
// %Y => Y : Four digit representation for the year
$dateTimeFormat = str_replace(array('%a', '%A', '%d', '%e', '%j', '%b', '%B', '%h', '%m', '%y', '%Y'), array('D', 'l', 'd', 'j', 'z', 'M', 'F', 'M', 'm', 'y', 'Y'), $this->format);
$dateTimeObject = date_create_from_format($dateTimeFormat, $value);
if ($dateTimeObject === FALSE) {
return FALSE;
}
return $value === $dateTimeObject->format($dateTimeFormat);
}
}
return TRUE;
}
开发者ID:khanhdeux,项目名称:typo3test,代码行数:38,代码来源:DateValidator.php
示例10: action
public function action($what, $cat, &$ret, $limit, $useGlobalCats)
{
$added = 0;
$url = 'http://torrentz.eu';
if ($useGlobalCats) {
$categories = array('all' => '', 'movies' => ' movies', 'tv' => ' tv', 'music' => ' music', 'games' => ' games', 'anime' => ' anime', 'software' => ' software', 'pictures' => ' pictures', 'books' => ' books');
} else {
$categories =& $this->categories;
}
if (!array_key_exists($cat, $categories)) {
$cat = $categories['all'];
} else {
$cat = $categories[$cat];
}
$maxPage = 10;
$updateMaxPage = true;
for ($pg = 0; $pg < $maxPage; $pg++) {
$cli = $this->fetch($url . '/search?q=' . $what . $cat . '&p=' . $pg);
if ($cli === false) {
break;
}
// max page
if ($updateMaxPage) {
$updateMaxPage = false;
if (!preg_match('`<a href="/search\\?q=[^"]*&p=\\d+">(?P<maxpage>\\d+)</a> <a href="/search\\?q=[^"]*&p=\\d+">Next »</a>`siU', $cli->results, $matches)) {
$maxPage = 0;
} else {
$maxPage = $matches["maxpage"];
}
}
// torrents
$res = preg_match_all('`<dl><dt.*><a href="/(?P<hash>[0-9a-fA-F]+?)">(?P<name>.+)</a> » ' . '(?P<cat>.*)</dt><dd>.*' . '<span class="a"><span title="(?P<date>.*)">.*</span></span>' . '<span class="s">(?P<size>.*)</span> <span class="u">(?P<seeds>.*)</span>' . '<span class="d">(?P<leech>.*)</span></dd></dl>' . '`siU', $cli->results, $matches);
if ($res) {
for ($i = 0; $i < $res; $i++) {
$link = "http://zoink.it/torrent/" . strtoupper($matches["hash"][$i]) . ".torrent";
if (!array_key_exists($link, $ret)) {
$item = $this->getNewEntry();
$item["cat"] = self::removeTags($matches["cat"][$i]);
$item["desc"] = $url . "/" . $matches["hash"][$i];
$item["name"] = self::removeTags($matches["name"][$i]);
$item["size"] = self::formatSize($matches["size"][$i]);
$item["seeds"] = intval($matches["seeds"][$i]);
$item["peers"] = intval($matches["leech"][$i]);
$tms = self::removeTags($matches["date"][$i]);
$tm = strptime($tms, '%a, %d %b %Y %T');
if ($tm !== false) {
$item["time"] = mktime($tm["tm_hour"], $tm["tm_min"], $tm["tm_sec"], $tm["tm_mon"] + 1, $tm["tm_mday"], $tm["tm_year"] + 1900);
}
$ret[$link] = $item;
$added++;
if ($added >= $limit) {
return;
}
}
}
} else {
break;
}
}
}
开发者ID:chaitanya11,项目名称:rtorrent,代码行数:60,代码来源:Torrentz.php
示例11: parseFormatedDate
/**
* @param string $str
* @return int
*/
private function parseFormatedDate($str)
{
KalturaLog::debug("parseFormatedDate({$str})");
if (function_exists('strptime')) {
$ret = strptime($str, self::BULK_UPLOAD_DATE_FORMAT);
if ($ret) {
KalturaLog::debug("Formated Date [{$ret}] " . date('Y-m-d\\TH:i:s', $ret));
return $ret;
}
}
$fields = null;
$regex = $this->getDateFormatRegex($fields);
$values = null;
if (!preg_match($regex, $str, $values)) {
return null;
}
$hour = 0;
$minute = 0;
$second = 0;
$month = 0;
$day = 0;
$year = 0;
$is_dst = 0;
foreach ($fields as $index => $field) {
$value = $values[$index + 1];
switch ($field) {
case 'Y':
$year = intval($value);
break;
case 'm':
$month = intval($value);
break;
case 'd':
$day = intval($value);
break;
case 'H':
$hour = intval($value);
break;
case 'i':
$minute = intval($value);
break;
case 's':
$second = intval($value);
break;
// case 'T':
// $date = date_parse($value);
// $hour -= ($date['zone'] / 60);
// break;
}
}
KalturaLog::debug("gmmktime({$hour}, {$minute}, {$second}, {$month}, {$day}, {$year})");
$ret = gmmktime($hour, $minute, $second, $month, $day, $year);
if ($ret) {
KalturaLog::debug("Formated Date [{$ret}] " . date('Y-m-d\\TH:i:s', $ret));
return $ret;
}
KalturaLog::debug("Formated Date [null]");
return null;
}
开发者ID:richhl,项目名称:kalturaCE,代码行数:63,代码来源:KAsyncBulkUpload.class.php
示例12: date_create_from_format
function date_create_from_format($format, $value)
{
$format = str_replace(array('Y', 'm', 'd', 'H', 'i', 'a'), array('%Y', '%m', '%d', '%I', '%M', '%p'), $format);
$ugly = strptime($value, $format);
$ymd = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, $ugly['tm_mon'] + 1, $ugly['tm_mday'], $ugly['tm_hour'], $ugly['tm_min'], $ugly['tm_sec']);
$d = new DateTime($ymd);
return $d;
}
开发者ID:varadourocultural,项目名称:portal,代码行数:8,代码来源:MY_Form_validation.php
示例13: trendoo_date_to_unix_timestamp
function trendoo_date_to_unix_timestamp($trendoo_date)
{
$res = strptime($trendoo_date, TRENDOO_DATE_TIME_FORMAT);
if ($res != false) {
return mktime($res['tm_hour'], $res['tm_min'], $res['tm_sec'], $res['tm_mon'], $res['tm_mday'], $res['tm_year'] + 1900);
} else {
return null;
}
}
开发者ID:iesportada,项目名称:intranet,代码行数:9,代码来源:util.php
示例14: strToTimestamp2
function strToTimestamp2($date, $format)
{
$decoded_date = strptime($date, dateFormatToStrftime($format));
if ($decoded_date !== false) {
return mktime($decoded_date['tm_hour'], $decoded_date['tm_min'], $decoded_date['tm_sec'], $decoded_date['tm_mon'] + 1, $decoded_date['tm_mday'], $decoded_date['tm_year'] + 1900);
} else {
return 0;
}
}
开发者ID:Kenovix,项目名称:san-miguel,代码行数:9,代码来源:sm_datetime.php
示例15: parse
public function parse($str)
{
//cut [ and ] if needed
$str = trim($str, '[]');
$time = strptime($str, $this->format);
if (!$time) {
return false;
}
return mktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year'] + 1900);
}
开发者ID:dariogs,项目名称:moosh,代码行数:10,代码来源:TimeElement.class.php
示例16: createFromFormat
/**
* Método de apoio, criado pois o php 5.2 não possui todos os metodos que são precisos
* @param string $dformat O formato do DateTime
* @param string $dvalue O tempo
* @return \DateTime
*/
public static function createFromFormat($dformat, $dvalue)
{
$schedule = $dvalue;
$schedule_format = str_replace(array('Y', 'm', 'd', 'H', 'i', 'a'), array('%Y', '%m', '%d', '%I', '%M', '%p'), $dformat);
// %Y, %m and %d correspond to date()'s Y m and d.
// %I corresponds to H, %M to i and %p to a
$ugly = strptime($schedule, $schedule_format);
$ymd = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, $ugly['tm_mon'] + 1, $ugly['tm_mday'], $ugly['tm_hour'], $ugly['tm_min'], $ugly['tm_sec']);
$new_schedule = new DateTime($ymd);
return $new_schedule;
}
开发者ID:andersongimino,项目名称:area51,代码行数:17,代码来源:Data.php
示例17: parse
public static function parse($str)
{
$formats = array('%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S', '%Y-%m-%dT%H:%M', '%Y-%m-%d %H:%M', '%Y-%m-%d');
foreach ($formats as $format) {
$time = strptime($str, $format);
if ($time !== false) {
return [self::parseStrptime($time), null];
}
}
return [null, true];
}
开发者ID:dxw,项目名称:php-missing,代码行数:11,代码来源:Dates.php
示例18: setValue
/**
* Sets control's value.
* @param string
* @return void
*/
public function setValue($value)
{
if (!is_array($value)) {
$value = strptime($value, $this->parseValueFormat());
// '%Y-%m-%d %H:%M'
}
if (isset($value['tm_year'])) {
$value['tm_year'] += 1900;
}
return parent::setValue($value);
}
开发者ID:romcok,项目名称:DateSelect,代码行数:16,代码来源:DateSelect.php
示例19: check_date
function check_date($date, $err_msg)
{
if ($date == null) {
return true;
}
$result = strptime($date, 'Y-m-d');
if ($date == false) {
return check_function_on_error($err_msg);
}
return true;
}
开发者ID:guirighetto,项目名称:BOCA_PROTEUM,代码行数:11,代码来源:function.check.php
示例20: xapp_is_datetime
/**
* check datetime string if valid. see xapp_is_date for more explanations since
* the this function does the same only with datetime values
*
* @param null|string $datetime expects datetime string to be checked for validity
* @param bool $strict expects boolean value to check against xapp config datetime format
* @return bool
*/
function xapp_is_datetime($datetime = null, $strict = false)
{
if ($datetime !== null) {
if ((bool) $strict) {
return (bool) @strptime($datetime, xapp_conf(XAPP_CONF_DATETIME_FORMAT));
} else {
return (bool) @strtotime((string) $datetime);
}
}
return false;
}
开发者ID:xamiro-dev,项目名称:xamiro,代码行数:19,代码来源:helper.php
注:本文中的strptime函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论