only convert to toISOString if time is valid code example Example: get iso date javascript var isoDate = new Date().toISOString()