Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q549 How can I convert a text string: "Wed Aug 26 14:40:45 MET DST 1998." into a Date object?

You are here: irt.org | FAQ | JavaScript | Date | Q549 [ previous next ]

The date foramt has to be altered to:

Wed, 26 Aug 1998 14:40:45

So:

<script language="JavaScript"><!--
var textdate = 'Wed Aug 26 14:40:45 MET DST 1998.';
var myArray = textdate.split(' ');
var input = myArray[0] + ', ' + myArray[2] + ' ' + myArray[1] + ' ' + myArray[3] + ' ' + myArray[6].substring(0,4);
var output = Date.parse(input);
var mydate = new Date(output)
//--></script>

©2018 Martin Webb