Sfoglia il codice sorgente

Date and time - Chamilo - CT#696

Guillaume Viguier 15 anni fa
parent
commit
cc12302f47
1 ha cambiato i file con 17 aggiunte e 0 eliminazioni
  1. 17 0
      main/inc/lib/main_api.lib.php

+ 17 - 0
main/inc/lib/main_api.lib.php

@@ -4410,6 +4410,23 @@ function api_convert_and_format_date($time = null, $format = null, $from_timezon
 	return api_format_date($time, $format);
 }
 
+/**
+ * Converts a string into a timestamp safely (handling timezones), using strtotime
+ * 
+ * @param string String to be converted
+ * @param string Timezone (if null, the timezone will be determined based on user preference, or timezone chosen by the admin for the platform)
+ * @return int Timestamp
+ * 
+ * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
+ */
+function api_strtotime($time, $timezone = null) {
+	$system_timezone = date_default_timezone_get();
+	date_default_timezone_set($timezone);
+	$timestamp = strtotime($time);
+	date_default_timezone_set($system_timezone);
+	return $timestamp;
+}
+
 /*	DEPRECATED FUNCTIONS */
 
 /**