sciris.sc_datetime.now

now(astype='dateobj', timezone=None, utc=False, tostring=False, dateformat=None)[source]

Get the current time as a datetime object, optionally in UTC time.

sc.now() is similar to sc.getdate(), but sc.now() returns a datetime object by default, while sc.getdate() returns a string by default.

Parameters
  • astype (str) – what to return; choices are “dateobj”, “str”, “float”; see sc.getdate() for more

  • timezone (str) – the timezone to set the itme to

  • utc (bool) – whether the time is specified in UTC time

  • dateformat (str) – if astype is 'str', use this output format

Examples:

sc.now() # Return current local time, e.g. 2019-03-14 15:09:26
sc.now(timezone='US/Pacific') # Return the time now in a specific timezone
sc.now(utc=True) # Return the time in UTC
sc.now(astype='str') # Return the current time as a string instead of a date object; use 'int' for seconds
sc.now(tostring=True) # Backwards-compatible alias for astype='str'
sc.now(dateformat='%Y-%b-%d') # Return a different date format

New in version 1.3.0: made “astype” the first argument; removed “tostring” argument