2016-05-18 6 views
0

Переменная returnMsg возвращается как {ts '2015- 03-04 9:10:00' } Однако мне нужно, чтобы представить данные, возвращаемые в виде строки „2015/03/04 9:10“Как вернуть значение временной метки из jQuery ajax-вызова из стиля {ts 'xxxx-xx-xx xx: xx: xx'} в строковый формат

 var myDate; 
     $.ajax({ 
      url: "../DateFunctions.cfc", 
      type:"POST", 
      cache: false, 
      dataType: "text", 
      async:false, 
      data: {method: "AddBusinessDays", 
        daysToAdd: DaysDue, 
        date: StartDate 

      }, 
      success: function(returnMsg) 
        { 
         try 
         { 
          var obj = new Date(returnMsg); 
          myDate = obj;   
         } 
         catch(e) 
         { 
          alert('AddBusinessDays Error parsing returnMsg'); 
         } 
        }, 
      error: function(httpRequest, textStatus, errorThrown) 
        { 
         alert("AddBusinessDays status=" + textStatus + ",error=" + errorThrown); 
        } 
     }); 

     return myDate; 

ответ

0

Один из способов заключается в использовании регулярного выражения для извлечения даты из строки.

var match = returnMsg.match(/\{ts '(.*)'\}/); 
var myDate = new Date(match[1]); 
Смежные вопросы