Get the current date-time

If no time zone is specified, then the default time zone will be used.

The default time zone is specified by the date.timezone INI setting or the date_default_timezone_set() function.
974038
static function dateTime(?\DateTimeZone $timezone = null): \DateTime
    {
        if (self::$now !== null) {
            $now = \DateTime::createFromFormat('U.u', sprintf('%.6F', self::$now));
            $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get()));

            return $now;
        }

        return new \DateTime('now', $timezone);
    }
937719
def ulocalized_gmt0_time(self, time, context, request):
        
        value = get_date(context, time)
        if not value:
            return ""
        # DateTime is stored with TimeZone, but DateTimeWidget omits TZ
        value = value.toZone("GMT+0")
        return self.ulocalized_time(value, context, request)
913903
def timezone(self):
        

        if not self._timezone_group and not self._timezone_location:
            return None

        if self._timezone_location != "":
            return "%s/%s" % (self._timezone_group, self._timezone_location)
        else:
            return self._timezone_group
270655
def _build_date_time_time_zone(self, date_time):
        
        timezone = date_time.tzinfo.zone if date_time.tzinfo is not None else None
        return {
            self._cc('dateTime'): date_time.strftime('%Y-%m-%dT%H:%M:%S'),
            self._cc('timeZone'): get_windows_tz(timezone or self.protocol.timezone)
        }
254832
public function getTimezone()
    {
        $dateTime = new Date();
        $dateTime->setTimeZone(new DateTimeZone($this->cachetTimezone));

        return $dateTime->format('T');
    }
274224
final protected function _getTimeZone($timezone = null)
	{
		if ($timezone = strtoupper($timezone) and defined("\\DateTimeZone::{$timezone}")) {
			$timezone = new \DateTimeZone($timezone);
		} elseif (! ($timezone instanceof \DateTimeZone)) {
			@date_default_timezone_set(date_default_timezone_get());
			$timezone = new \DateTimeZone(date_default_timezone_get());
		}
		return $timezone;
	}
1190312
def set_timezone(self, timezone: str):
        
        data = {"timezoneId": timezone}
        return self._restCall("home/setTimezone", body=json.dumps(data))
1243541
public static TimeZone getUserTimeZone()
    {
        TimeZone ret = null;

        // First try the configured timezone
        String tz = DEFAULT_TIMEZONE;
        ret = AppTimeZone.getTimeZoneById(tz);
        if(ret == null)
        {
            // Next try the locale timezone
            tz = System.getProperty("user.timezone");

            // Next try the default timezone
            if(tz == null || tz.length() == 0)
                ret = TimeZone.getDefault();
            else if(tz.equals("GMT"))
                ret = tzBST;                     // Use BST instead of GMT
            else
                ret = TimeZone.getTimeZone(tz);  // Otherwise use the standard TZ
        }

        return ret;
    }
908228
private function client_timezone()
    {
        // @TODO: remove this legacy timezone handling in the future
        $props = $this->fix_legacy_props(array('timezone' => $_SESSION['timezone']));

        if (!empty($props['timezone'])) {
            try {
                $tz = new DateTimeZone($props['timezone']);
                return $tz->getName();
            }
            catch (Exception $e) { /* gracefully ignore */ }
        }

        // fallback to server's timezone
        return date_default_timezone_get();
    }
885857
def current_time(self) -> datetime:
        """"""
        _date = datetime.strptime(self.obj.SBRes.SBReq.StartT.get("date"), "%Y%m%d")
        _time = datetime.strptime(self.obj.SBRes.SBReq.StartT.get("time"), "%H:%M")
        return datetime.combine(_date.date(), _time.time())
225971
def timezone(self, value):
        """"""
        self._timezone = (value if isinstance(value, datetime.tzinfo)
                          else tz.gettz(value))
1028132
protected function getUTCTimezone()
    {
        if (\date_default_timezone_get() == 'UTC') {
            return 'UTC'; //already in UTC. workaround as zone must be non empty
        }
         
        $timezone = new \DateTimeZone(\date_default_timezone_get()); // Get default system timezone to create a new DateTimeZone object
        $offset = $timezone->getOffset(new \DateTime()); // Offset in seconds to UTC
        $offsetHours = round(abs($offset) / 3600);
        $offsetMinutes = round((abs($offset) - $offsetHours * 3600) / 60);
        $offsetString = ($offset < 0 ? '-' : '+')
            . ($offsetHours < 10 ? '0' : '') . $offsetHours
            . ($this->format == C::FORMAT_EXTENDED || $this->format == C::FORMAT_EXTENDED_SIGNED ? ':' : '')
            . ($offsetMinutes < 10 ? '0' : '') . $offsetMinutes;

        return $offsetString;
    }
521178
def date(self):
        ''' 
        '''
        utcnow = datetime.utcnow()
        return (utcnow + timedelta(hours=self.time_zone)).date()
158617
def datetime(self, field=None, val=None):
        
        if val is None:
            def source():
                tzinfo = get_default_timezone() if settings.USE_TZ else None
                return datetime.fromtimestamp(randrange(1, 2100000000),
                                              tzinfo)
        else:
            def source():
                tzinfo = get_default_timezone() if settings.USE_TZ else None
                return datetime.fromtimestamp(int(val.strftime("%s")) +
                                              randrange(-365*24*3600*2, 365*24*3600*2),
                                              tzinfo)
        return self.get_allowed_value(source, field)
488636
def now(self):
		
		if self.use_utc:
			return datetime.datetime.utcnow()
		else:
			return datetime.datetime.now()
1029558
def get_datetimenow(self):
        
        value = timezone.datetime.utcnow()
        if settings.USE_TZ:
            value = timezone.localtime(
                timezone.make_aware(value, timezone.utc),
                timezone.get_default_timezone()
            )
        return value
218243
public function getTimezone() : ?string 
    {
        if ( ! $this->hasTimezone()) {
            $this->setTimezone($this->getDefaultTimezone());
        }
        return $this->timezone;
    }