Get Date details (day, month, year) in GWT

后端 未结 4 649
粉色の甜心
粉色の甜心 2021-01-04 01:22

I need to get the day, month, year details from a Date value but getYear() is deprecated, gives year on 2 digits, and has problems with Y2K (2008 g

4条回答
  •  梦谈多话
    2021-01-04 01:49

    The workaround presented by Ashwin works and it's not that tricky. But I'd suggest using the date patterns instead of splitting:

    For date - 
    DateTimeFormat.getFormat( "d" ).format( new Date() )
    
    For month - 
    DateTimeFormat.getFormat( "M" ).format( new Date() )
    
    For year - 
    DateTimeFormat.getFormat( "yyyy" ).format( new Date() )
    

提交回复
热议问题