So I'm beginner with js and regexps are a sore spot for me. I need to remove a timestamp from my dropdowns. Here is how it appears:
<option value="Aqua">
<span>Aqua - Available to ship 2013-05-29 01:02:00.0 - $18.00</span>
</option>
I have an if
statement appending the Available to ship text and the date at the end. Essentially the only think I need to grab is the date. So I'm thinking I could either just chop off everything after the date or remove the timestamp with a regex. The issue is I'm having a lot of trouble getting either of these to work. Here is my if statement.
if ((index == selectors.length || (selectors.length > 1 && key !== 'color')) && product.availability.online.fulfillment != null) {
var date = product.availability.online.fulfillment
value.text = product.options[key] + ' - Available to ship ' + date + ' - $' + product.price.value;
}
Thanks in advance!
To remove:
date = date.substring(0, date.indexOf(' '));
Regex replace:
date = date.replace(/[01][0-9]:[0-5][0-9]:[0-9]{2}.[0-9]/, '');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.