Changeset 19974 for trunk/wp-includes/functions.php
- Timestamp:
- 02/21/2012 08:03:11 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r19973 r19974 9 9 10 10 /** 11 * Converts MySQL DATETIME field to user specified date format. 12 * 13 * The $translate parameter will only be used, if it is set to true and it is by 14 * default and if the $wp_locale object has the month and weekday set. 11 * Converts given date string into a different format. 12 * 13 * $format should be either a PHP date format string, e.g. 'U' for a Unix 14 * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT. 15 * 16 * If $translate is true then the given date and format string will 17 * be passed to date_i18n() for translation. 15 18 * 16 19 * @since 0.71 17 20 * 18 * @param string $dateformatstring Either 'G', 'U', or PHP date format. 19 * @param string $mysqlstring Time from mysql DATETIME field. 20 * @param bool $translate Optional. Default is true. Will switch format to locale. 21 * @return string Date formatted by $dateformatstring or locale (if available). 22 */ 23 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { 24 $m = $mysqlstring; 25 if ( empty( $m ) ) 21 * @param string $format Format of the date to return. 22 * @param string $date Date string to convert. 23 * @param bool $translate Whether the return date should be translated. Default is true. 24 * @return string|int Formatted date string, or Unix timestamp. 25 */ 26 function mysql2date( $format, $date, $translate = true ) { 27 if ( empty( $date ) ) 26 28 return false; 27 29 28 if ( 'G' == $ dateformatstring)29 return strtotime( $ m. ' +0000' );30 31 $i = strtotime( $ m);32 33 if ( 'U' == $ dateformatstring)30 if ( 'G' == $format ) 31 return strtotime( $date . ' +0000' ); 32 33 $i = strtotime( $date ); 34 35 if ( 'U' == $format ) 34 36 return $i; 35 37 36 38 if ( $translate ) 37 return date_i18n( $ dateformatstring, $i );39 return date_i18n( $format, $i ); 38 40 else 39 return date( $ dateformatstring, $i );41 return date( $format, $i ); 40 42 } 41 43
Note: See TracChangeset
for help on using the changeset viewer.