2013-02-24 60 views

回答

1

您可以解析月份名稱日期與Date普通解析功能:

new Date().parse("MMM", "Feb") 
1

你可以這樣做:

String monthString = 'Feb' 

int month = Calendar.instance.with { 
    time = new Date().parse("MMM", monthString) 
    it[ MONTH ] 
} 

// Feb is 1 of course, not 2 as in your question 
assert month == 1 
6

呼叫Date.parseMMM作爲格式字符串。這會給你一個Date對象,它提供月份號碼的訪問權限。例如:

def d = Date.parse('MMM', 'Feb') 
def num = d.format('MM') as int 
assert num == 2 
+0

從0開始的地獄般的Java約定逃脫了! – epidemian 2013-02-24 17:37:55