#
Time
1.0.3+
#
TeslaCloud.TIme
#
Flags
#
Properties
#
timeToObject
Converts time in seconds to years, months, days, hours, minutes and seconds.
timeToObject(time, flags = this.ALL)
#
Arguments
#
Examples
#
Simple conversion
console.log(
TeslaCloud.Time.timeToObject(
13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000
)
);
/*
Object<TeslaCloud.DateInterval>
{
years: 3,
months: 1,
days: 0,
hours: 14,
minutes: 37,
seconds: 13,
invert: false
}
*/
#
Retrieving only certain values
const TCT = TeslaCloud.Time;
console.log(
TCT.timeToObject(
13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
TCT.DAYS | TCT.HOURS | TCT.MINUTES
)
);
/*
Object<TeslaCloud.DateInterval>
{
years: 0,
months: 0,
days: 1125,
hours: 14,
minutes: 37,
seconds: 0,
invert: false
}
*/
#
timeToString
Converts a time to a string.
timeToString(time, format = this.FORMAT_STR, flags = this.ALL | this.NO_FIRST_ZEROS)
#
Arguments
#
Examples
#
Simple conversion
console.log(
TeslaCloud.Time.timeToString(
13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000
)
);
// 3 years 1 month 0 days 14 hours 37 minutes 13 seconds
#
Removing all zeros from results
const TCT = TeslaCloud.Time;
console.log(
TCT.timeToString(
13 + 37 * 60 + 14 * 3600 + 30 * 86400,
TCT.FORMAT_STR,
TCT.ALL | TCT.NO_ZEROS
)
);
// 1 month 14 hours 37 minutes 13 seconds
#
Retrieving only certain values
const TCT = TeslaCloud.Time;
console.log(
TCT.timeToString(
13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
TCT.FORMAT_STR,
TCT.DAYS | TCT.HOURS | TCT.MINUTES
)
);
// 1 125 days 14 hours 37 minutes
#
Custom format
const TCT = TeslaCloud.Time;
console.log(
TCT.timeToString(
13 + 37 * 60 + 14 * 3600 + 30 * 86400 + 3 * 31536000,
'{hours}:{minutes}:{seconds}',
TCT.HOURS | TCT.MINUTES | TCT.SECONDS
)
);
// 27014:37:13
#
diff
Returns the difference between two dates.
diff(one, two, absolute = false)
#
Arguments
#
Return values
Returns a
#
Examples
const TCT = TeslaCloud.Time;
console.log(
TCT.diff(Date.now(), 'January 19, 2038 03:14:08 UTC')
);
/*
Object<TeslaCloud.DateInterval>
{
years: 13,
months: 11,
days: 8,
hours: 4,
minutes: 14,
seconds: 2,
invert: false
}
*/
console.log(
TCT.diff(Date.now(), 'October 7, 2005')
);
/*
Object<TeslaCloud.DateInterval>
{
years: 18,
months: 4,
days: 4,
hours: 3,
minutes: 3,
seconds: 49,
invert: true
}
*/
#
TeslaCloud.DateInterval
Represents the difference between the two dates
#
Properties
#
isZero
Returns true
if all values of the object are zero, otherwise false
.
#
TeslaCloud.Countdown (tc-countdown)
#
Parameters
#
Examples
<xf:js src="TC/ComponentLibrary/time.js" addon="TC/ComponentLibrary" min="1" />
<dl class="pairs pairs--spaced">
<dt>Countdown to January 19, 2038 03:14:08 UTC</dt>
<dd>
<span data-xf-init="tc-countdown"
data-to="January 19, 2038 03:14:08 UTC">Initialization...</span>
</dd>
</dl>
<dl class="pairs pairs--spaced">
<dt>Countdown to October 7, 2005</dt>
<dd>
<span data-xf-init="tc-countdown"
data-to="10.07.2005">Initialization...</span>
</dd>
</dl>
<dl class="pairs pairs--spaced">
<dt>Countdown to January 19, 2038 03:14:08 UTC with custom format</dt>
<dd>
<span data-xf-init="tc-countdown"
data-to="January 19, 2038 03:14:08 UTC"
data-format="The Epochalipse will come in {$xf.tcTime.FORMAT_STR}"
data-format-negative="The Epochalpse came {{ phrase('tc_clib_x_ago', {'time': $xf.tcTime.FORMAT_STR}) }}">Initialization...</span>
</dd>
</dl>
<dl class="pairs pairs--spaced">
<dt>Countdown to January 1, 2025 without negative interval</dt>
<dd>
<span data-xf-init="tc-countdown"
data-to="January 1, 2025"
data-allow-negative="false"
data-end-text="The countdown is over">Initialization...</span>
</dd>
</dl>Pluralization [!badge variant="info" text="1.0.3+"]Pluralization [!badge variant="info" text="1.0.3+"]