---
category: utilities
---
Converts a unit value time combination (s, ms) to a number representing ms

@module ms

Example inputs:
- '100s'
- '20ms'

@param {String} val
@returns {Number} Returns numerical representation of milliseconds
160861
function ms (val) {
  if (!val || typeof val === 'number') {
    return val
  }

  const [ num, unit ] = parseUnit(val)

  if (unit === 'ms') {
    return num
  } else if (unit === 's') {
    return num * 1000
  } else {
    return num
  }
}
1242040
def _microtime():
    '''
    
    '''
    val1, val2 = math.modf(time.time())
    val2 = int(val2)
    return '{0:f}{1}'.format(val1, val2)
354923
function parseTimeStamp(input) {

    function computeSeconds(h, m, s, f) {
      return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
    }

    var m = input.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);
    if (!m) {
      return null;
    }

    if (m[3]) {
      // Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
      return computeSeconds(m[1], m[2], m[3].replace(":", ""), m[4]);
    } else if (m[1] > 59) {
      // Timestamp takes the form of [hours]:[minutes].[milliseconds]
      // First position is hours as it's over 59.
      return computeSeconds(m[1], m[2], 0,  m[4]);
    } else {
      // Timestamp takes the form of [minutes]:[seconds].[milliseconds]
      return computeSeconds(0, m[1], m[2], m[4]);
    }
  }
600003
def convert(cls, value, from_unit, to_unit):
        
        value_ms = value * cls.UNITS_IN_MILLISECONDS[from_unit]
        return value_ms / cls.UNITS_IN_MILLISECONDS[to_unit]
1065269
@Pure
	public static double toSeconds(double value, TimeUnit inputUnit) {
		switch (inputUnit) {
		case DAYS:
			return value * 86400.;
		case HOURS:
			return value * 3600.;
		case MINUTES:
			return value * 60.;
		case SECONDS:
			break;
		case MILLISECONDS:
			return milli2unit(value);
		case MICROSECONDS:
			return micro2unit(value);
		case NANOSECONDS:
			return nano2unit(value);
		default:
			throw new IllegalArgumentException();
		}
		return value;
	}
489209
function getTimestampString(date) {
    // all this nasty code is faster (~30k ops/sec) than doing "moment(date).format('HH:mm:ss:SSS')" and means 0 dependencies
    var hour = '0' + date.getHours();
    hour = hour.slice(hour.length - 2);
    var minute = '0' + date.getMinutes();
    minute = minute.slice(minute.length - 2);
    var second = '0' + date.getSeconds();
    second = second.slice(second.length - 2);
    var ms = '' + date.getMilliseconds();

    // https://github.com/MarkHerhold/palin/issues/6
    // this is faster than using an actual left-pad algorithm
    if (ms.length === 1) {
        ms = '00' + ms;
    } else if (ms.length === 2) {
        ms = '0' + ms;
    } // no modifications for 3 or more digits

    return chalk.dim(`${hour}:${minute}:${second}:${ms}`);
}
394781
function(val, fractionDigits)
    {
      return val == null || val === "" ? 0 : formatNumber(val,
      {
        minimumFractionDigits: fractionDigits == null ? 0 : fractionDigits,
        maximumFractionDigits: fractionDigits == null ? maximumFractionDigits : fractionDigits
      })
    }
651683
def end_of_month(val):
    
    if type(val) == date:
        val = datetime.fromordinal(val.toordinal())
    if val.month == 12:
        return start_of_month(val).replace(year=val.year + 1, month=1) \
               - timedelta(microseconds=1)
    else:
        return start_of_month(val).replace(month=val.month + 1) \
               - timedelta(microseconds=1)
601783
def convert_timeval(seconds_since_epoch):
    """"""
    frac, whole = math.modf(seconds_since_epoch)
    microseconds = math.floor(frac * 1000000)
    seconds = math.floor(whole)
    return seconds, microseconds
335915
function (value) {
        let val = parseInt(value, 10);
        if (isNaN(val)) {
            return false;
        }
        return (val + '').length === value.length;
    }
639766
function toFloat(val, def) {
    if (is_1.isFloat(val))
        return val;
    if (!is_1.isValue(val))
        return toDefault(null, def);
    var parsed = function_1.tryWrap(parseFloat, val)(def);
    if (is_1.isFloat(parsed) || is_1.isNumber(parsed))
        return parsed;
    if (toBoolean(val))
        return 1;
    return 0;
}
758423
function Date(Y, M, D, h, m, s, ms) {
                var length = arguments.length;
                var date;
                if (this instanceof NativeDate) {
                    var seconds = s;
                    var millis = ms;
                    if (hasSafariSignedIntBug && length >= 7 && ms > maxSafeUnsigned32Bit) {
                        // work around a Safari 8/9 bug where it treats the seconds as signed
                        var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
                        var sToShift = Math.floor(msToShift / 1e3);
                        seconds += sToShift;
                        millis -= sToShift * 1e3;
                    }
                    date = length === 1 && $String(Y) === Y ? // isString(Y)
                        // We explicitly pass it through parse:
                        new NativeDate(DateShim.parse(Y)) :
                        // We have to manually make calls depending on argument
                        // length here
                        length >= 7 ? new NativeDate(Y, M, D, h, m, seconds, millis) :
                        length >= 6 ? new NativeDate(Y, M, D, h, m, seconds) :
                        length >= 5 ? new NativeDate(Y, M, D, h, m) :
                        length >= 4 ? new NativeDate(Y, M, D, h) :
                        length >= 3 ? new NativeDate(Y, M, D) :
                        length >= 2 ? new NativeDate(Y, M) :
                        length >= 1 ? new NativeDate(Y instanceof NativeDate ? +Y : Y) :
                                      new NativeDate();
                } else {
                    date = NativeDate.apply(this, arguments);
                }
                if (!isPrimitive(date)) {
                    // Prevent mixups with unfixed Date object
                    defineProperties(date, { constructor: DateShim }, true);
                }
                return date;
            }
723456
def _to_numeric(val):
    
    if isinstance(val, (int, float, datetime.datetime, datetime.timedelta)):
        return val
    return float(val)
983747
def parse_time(val):
    
    dt = parse_date(val)
    if dt.tzinfo is None:
        return dt.time()
    return datetime.time(dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
634988
function parseTransitionValue(values) {
  if (typeof values === 'string') values = values.trim().split(/\s*,\s*/g);
  var ret = [];

  for (var i = 0; i < values.length; i++) {
    var value = values[i].toString();

    if (value === 'initial') {
      value = 0;
    } else if (/ms$/.test(value)) {
      value = parseFloat(value) / 1000;
    } else {
      value = parseFloat(value);
    }

    ret.push(value);
  }

  return ret;
}
1198042
def _seconds_to_days(cls, val, **kwargs):
        '''
        
        '''
        zero_value = kwargs.get('zero_value', 0)
        if val is not None:
            if val == zero_value:
                return 0
            return val / 86400
        else:
            return 'Not Defined'
777194
function convert(time) {
      var hour;
      var minute;
      hour = Math.floor(time / 60);
      if (time % 60 === 0) {
        minute = 0;
      } else {
        minute = time % 60;
      }
      return hour + ':' + (minute < 10 ? ('0' + minute) : minute);
    }