WC_Product_CSV_Importer::parse_datetime_field()
Parse dates from a CSV. Dates can be Unix timestamps or in any format supported by strtotime().
Метод класса: WC_Product_CSV_Importer{}
Хуков нет.
Возвращает
Строку|null
.
Использование
$WC_Product_CSV_Importer = new WC_Product_CSV_Importer(); $WC_Product_CSV_Importer->parse_datetime_field( $value );
- $value(строка) (обязательный)
- Field value.
Код WC_Product_CSV_Importer::parse_datetime_field() WC Product CSV Importer::parse datetime field WC 9.8.2
public function parse_datetime_field( $value ) { try { // If value is a Unix timestamp, convert it to a datetime string. if ( is_numeric( $value ) ) { $datetime = new DateTime( "@{$value}" ); // Return datetime string in ISO8601 format (eg. 2018-01-01T00:00:00Z) to preserve UTC timezone since Unix timestamps are always UTC. return $datetime->format( 'Y-m-d\TH:i:s\Z' ); } // Check whether the value is a valid date string. if ( false !== strtotime( $value ) ) { // If the value is a valid date string, return as is. return $value; } } catch ( Exception $e ) { // DateTime constructor throws an exception if the value is not a valid Unix timestamp. return null; } // If value is not valid Unix timestamp or date string, return null. return null; }