Changeset 45856 for trunk/src/wp-includes/functions.php
- Timestamp:
- 08/19/2019 09:05:42 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r45854 r45856 47 47 48 48 /** 49 * Retrieve the current time based on specified type.49 * Retrieves the current time based on specified type. 50 50 * 51 51 * The 'mysql' type will return the time in the format for MySQL DATETIME field. 52 * The 'timestamp' type will return the current timestamp. 52 * The 'timestamp' type will return the current timestamp or a sum of timestamp 53 * and timezone offset, depending on `$gmt`. 53 54 * Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d'). 54 55 * … … 64 65 */ 65 66 function current_time( $type, $gmt = 0 ) { 66 switch ( $type ) { 67 case 'mysql': 68 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); 69 case 'timestamp': 70 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 71 default: 72 return ( $gmt ) ? gmdate( $type ) : gmdate( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); 73 } 67 // Don't use non-GMT timestamp, unless you know the difference and really need to. 68 if ( 'timestamp' === $type || 'U' === $type ) { 69 return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 70 } 71 72 if ( 'mysql' === $type ) { 73 $type = 'Y-m-d H:i:s'; 74 } 75 76 $timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone(); 77 $datetime = new DateTime( 'now', $timezone ); 78 79 return $datetime->format( $type ); 74 80 } 75 81
Note: See TracChangeset
for help on using the changeset viewer.