I have a str variable (string type) that has the value "28-Nov-2013 09:15 AM". How to convert it to UTC format (the above value in str variable is in PST, therefore, UTC should be 8 hours longer). I am using flex 2. The figure below shows the code that does not work: -
txtDate.text= formatDateUTC(txtDate.text); //here txtDate.text=28-Nov-2013 09:15 AM private function formatDateUTC(originalDate:String):String { Alert.show('original '+originalDate); var dtValue:Date = new Date(Date.parse(originalDate.replace("-"," "))); var editedDate:String=pstFormatter.format(dtValue); Alert.show('edited '+editedDate); return (dateFormatter.format(dateAdd("hours",8,dtValue))).toString(); } private function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date { if (date == null) { date = new Date(); } var returnDate:Date = new Date(date);; switch (datepart.toLowerCase()) { case "fullyear": case "month": case "date": case "hours": case "minutes": case "seconds": case "milliseconds": returnDate[datepart] += number; break; default: /* Unknown date part, do nothing. */ break; } return returnDate; }
user3005581
source share