2010-08-22 18 views

cevap

10

java.util.Date sınıfındaki yöntemlerle: parse(String s) ve toString(). İlk kullanımdan kaldırılmış olsa da, GWT ile kullanılacak yöntemdir. Tarihin nasıl biçimlendirileceği konusunda daha fazla denetim istiyorsanız, String'e dönüştürürken GWT'ye özgü sınıfı kullanın: com.google.gwt.i18n.client.DateTimeFormat. Java'nın kendi SimpleDateFormat sürümüne benzer bir desen verilen tarihi biçimlendirir.

4
import com.google.gwt.i18n.shared.DateTimeFormat; 
import java.util.Date; 

... 

public Date getDate(String dateString) { 
    Date result = null; 
    try { 
     DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd"); 
     result = dateTimeFormat.parse(dateString); 
    } catch (Exception e) 
    { 
     // ignore 
    } 
    return result; 
} 
1

StringFormat için tarihi dönüştürmek için

import com.google.gwt.i18n.shared.DateTimeFormat; 
    import java.util.Date; 

    ... 
    public String getStringFormat(Date inputDate){ 
    String strFormat = null; 
    try{ 
    DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("DD-MMM-YYYY"); 
    strFormat = dateTimeFormat.format(inputDate); 
    }catch(Exception e){ 
    e.printStackTrace(); 
    } 
    return strFormat; 
    } 
İlgili konular