本文整理汇总了PHP中strptime函数的典型用法代码示例。如果您正苦于以下问题:PHP strptime函数的具体用法?PHP strptime怎么用?PHP strptime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strptime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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";
}
}
示例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;
}
示例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']);
}
示例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;
}
示例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');
}
}
示例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;
}
示例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.'));
}
示例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();
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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);
}