Function Repository Resource:

# SecondsToQuantity

Convert a number representing seconds to a quantity of time in an appropriate unit

Contributed by: Richard Hennigan (Wolfram Research)
 ResourceFunction["SecondsToQuantity"][int] converts an integer int representing seconds to a Quantity object using an appropriate unit. ResourceFunction["SecondsToQuantity"][Quantity[…]] converts a quantity of time into an appropriate compatible unit.

## Details and Options

ResourceFunction["SecondsToQuantity"] accepts the following options:
 "MixedUnits" True whether to allow MixedUnit in the output "MaxMixedUnits" Automatic specifies the maximum number of units to use in MixedUnit outputs

## Examples

### Basic Examples (2)

Convert a number of seconds into a Quantity object:

 In[1]:=
 Out[1]=

Convert a Quantity object representing time into an easier-to-read unit:

 In[2]:=
 Out[2]=
 In[3]:=
 Out[3]=

### Scope (3)

For symbolic values, the result is just a Quantity of seconds:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

Convert an approximate value represented as an Around object:

 In[6]:=
 Out[6]=

Convert a range of values represented by an Interval object:

 In[7]:=
 Out[7]=

### Options (5)

#### MixedUnits (2)

By default, SecondsToQuantity can return MixedUnit in the output:

 In[8]:=
 Out[8]=

 In[9]:=
 Out[9]=

#### MaxMixedUnits (3)

By default, the number of units used in MixedUnit outputs is limited:

 In[10]:=
 Out[10]=

Restrict to a maximum of two units:

 In[11]:=
 Out[11]=

Show all available mixed units:

 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=

Using "MaxMixedUnits"1 is effectively equivalent to "MixedUnits"False:

 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=

### Applications (2)

Improve the readability of the output for functions that return time as a number of seconds:

 In[16]:=
 Out[16]=
 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=
 In[19]:=
 Out[19]=

Convert the number of seconds since January 1, 1970, in the GMT time zone to more readable units:

 In[20]:=
 Out[19]=

### Properties and Relations (1)

The resource function RelativeTimeString uses SecondsToQuantity to convert units:

 In[21]:=
 Out[21]=
 In[22]:=
 Out[22]=

### Possible Issues (3)

MixedUnit values are not used for values that are very large or very small:

 In[23]:=
 Out[23]=
 In[24]:=
 Out[24]=

With the default setting of "MaxMixedUnits"Automatic, mixed units are not used for Interval or Around objects:

 In[25]:=
 Out[25]=
 In[26]:=
 Out[26]=

Specify a positive value to override the default behavior:

 In[27]:=
 Out[27]=
 In[28]:=
 Out[28]=

Units must be compatible:

 In[29]:=
 Out[29]=

## Version History

• 1.2.0 – 06 March 2023
• 1.1.0 – 04 March 2021
• 1.0.0 – 27 January 2020