Click to See Complete Forum and Search --> : How to parse a string to Date()?


jmfei
10-07-2003, 02:53 AM
for example:
a textbox with value of '2003-10-7'
a select with selectItem's value of 12
a select with selectItem's value of 24
and how can I change it to Date format of '2003-10-7 12:24:00"

Thanks a lot!

Charles
10-07-2003, 05:33 AM
<script type="text/javascript">
<!--
Date.fromW3CDTF = function (s) {var a = s.split('-'); return new Date(a[0], ++a[1], a[2])};

Date.prototype.toString = function () {return [[this.getFullYear(), this.getMonth() < 9 ? '0' + Number(this.getMonth() + 1) : Number(this.getMonth() + 1), this.getDay() < 10 ? '0' + this.getDay() : this.getDay()].join('-'), [this.getHours() < 10 ? '0' + this.getHours() : this.getHours(), this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join(':')].join(' ')};

then = Date.fromW3CDTF('2003-10-7');
then.setHours(12);
then.setMinutes(24);
alert(then);
// -->
</script>