Use instanceof for class-based checks like Date. Combine it with typeof to handle other primitives. Return a single number so callers can compare times.
function toMs(v: Date | number) {
return v instanceof Date ? v.getTime() : v;
}
Parse strings using Date.parse which returns milliseconds since the epoch. Keep behavior simple and explicit.
Convert different time inputs into milliseconds.