本文整理匯總了PHP中Bitrix\Main\Type\DateTime::convertFormatToPhp方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTime::convertFormatToPhp方法的具體用法?PHP DateTime::convertFormatToPhp怎麽用?PHP DateTime::convertFormatToPhp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Bitrix\Main\Type\DateTime
的用法示例。
在下文中一共展示了DateTime::convertFormatToPhp方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convertTo
/**
* @param FieldType $fieldType Document field type.
* @param mixed $value Field value.
* @param string $toTypeClass Type class name.
* @return null|mixed
*/
public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
{
/** @var Base $toTypeClass */
$type = $toTypeClass::getType();
switch ($type) {
case FieldType::BOOL:
$value = (bool) $value ? 'Y' : 'N';
break;
case FieldType::DATE:
$value = date(Main\Type\Date::convertFormatToPhp(\FORMAT_DATE), (int) $value);
break;
case FieldType::DATETIME:
$value = date(Main\Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), (int) $value);
break;
case FieldType::DOUBLE:
$value = (double) $value;
break;
case FieldType::INT:
$value = (int) $value;
break;
case FieldType::STRING:
case FieldType::TEXT:
$value = (string) $value;
break;
case FieldType::USER:
$value = 'user_' . (int) $value;
break;
default:
$value = null;
}
return $value;
}
示例2: convertTo
/**
* @param FieldType $fieldType Document field type.
* @param mixed $value Field value.
* @param string $toTypeClass Type class name.
* @return null|mixed
*/
public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
{
/** @var Base $toTypeClass */
$type = $toTypeClass::getType();
switch ($type) {
case FieldType::DOUBLE:
case FieldType::INT:
$value = $value ? (int) strtotime($value) : 0;
break;
case FieldType::DATE:
$value = date(Type\Date::convertFormatToPhp(\FORMAT_DATE), strtotime($value));
break;
case FieldType::DATETIME:
$value = date(Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), strtotime($value));
break;
case FieldType::STRING:
case FieldType::TEXT:
$value = (string) $value;
if ($value) {
$format = static::getType() == FieldType::DATE ? \FORMAT_DATE : \FORMAT_DATETIME;
$value = date(Type\DateTime::convertFormatToPhp($format), strtotime($value));
}
break;
default:
$value = null;
}
return $value;
}
示例3: convertTo
/**
* @param FieldType $fieldType Document field type.
* @param mixed $value Field value.
* @param string $toTypeClass Type class name.
* @return null|mixed
*/
public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
{
/** @var Base $toTypeClass */
$type = $toTypeClass::getType();
switch ($type) {
case FieldType::BOOL:
$value = strtolower((string) $value);
$value = in_array($value, array('y', 'yes', 'true', '1')) ? 'Y' : 'N';
break;
case FieldType::DATE:
$value = date(Main\Type\Date::convertFormatToPhp(\FORMAT_DATE), strtotime($value));
break;
case FieldType::DATETIME:
$value = date(Main\Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), strtotime($value));
break;
case FieldType::DOUBLE:
$value = str_replace(' ', '', str_replace(',', '.', $value));
$value = (double) $value;
break;
case FieldType::INT:
$value = str_replace(' ', '', $value);
$value = (int) $value;
break;
case FieldType::STRING:
case FieldType::TEXT:
$value = (string) $value;
break;
case FieldType::USER:
$value = trim($value);
if (strpos($value, 'user_') === false && strpos($value, 'group_') === false && !preg_match('#^[0-9]+$#', $value)) {
$value = null;
}
break;
default:
$value = null;
}
return $value;
}