2013-02-06 3 views
1

Jquery/Javascript에서 날짜 형식을 변경하는 방법은 무엇입니까?Jquery/Javascript에서 날짜 형식을 변경하는 방법은 무엇입니까?

나는 date.js을 다운로드했습니다. 그럼, 예를 아래에 따르

Thu Jan 31 2013 16:29:30 GMT+0700 (WIT)

var d1 = Date.parse("Thu Jan 31 2013 16:29:30 GMT+0700 (WIT)"); 
alert(d1.toString('dd/mm/yyyy')); 

내 로그 캣 인쇄이 : I가 폰갭을 사용

CordovaLog(31455): Uncaught RangeError: toString() radix argument must be between 2 and 36

var d1 = Date.parse('2010-10-18, 10:06 AM'); 
alert(d1.toString('dd/mm/yyyy HH:mm:ss GMT')); 

그래서 나는 다음과 같은 날짜에 대한 내 자신의 코드를 작성 내 안드로이드 응용 프로그램.

+0

대신 순간을 사용해보십시오. http://momentjs.com/에서 날짜 구문 분석 및 서식 지정을하는 것이 좋습니다. JavaScript에서 JodaTime과 가장 가까운 것으로 momentjs가 표시됩니다. 또 다른 옵션은 [jquery datepicker] (http://docs.jquery.com/UI/Datepicker/formatDate)의 날짜 양식기를 사용하는 것이지만 momentjs가 더 좋습니다. – fmsf

+0

저는 momentjs에 관심이 많았지 만 문서가 너무 길어 타임 스탬프에서 포맷 된 날짜로 변환 할 방법을 찾지 못했습니다. – Rendy

+0

순간 (TimeStampInMillis). 형식 ('DD/MM/YYYY') – fmsf

답변

-1

JavaScript를 사용하여 날짜와 시간의 서식을 지정할 수 있습니다. http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3

function formatDate(date) { 
    var d1 = Date.parse(date); 
    var d = new Date(d1); 
    var curr_date = d.getDate(); 
    if (curr_date.toString().length == 1) { 
     curr_date = "0" + curr_date; 
    } 
    var curr_month = d.getMonth(); 
    curr_month++; 
    if (curr_month.toString().length == 1) { 
     curr_month = "0" + curr_month; 
    } 
    var curr_year = d.getFullYear(); 
    console.log(curr_date + "/" + curr_month + "/" + curr_year); 
} 

formatDate("Thu Jan 31 2013 16:29:30 GMT+0700 (WIT)"); 
//Returns the date in "dd/mm/yyyy" format 
0

시도이 ..

var d = new Date(); 
var newDate = d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear(); 

alert('newDate '+newDate); 
관련 문제