本文整理汇总了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;
}