开发者

How to transform the data from one format to another format

I have my date in this format开发者_StackOverflow yyyy-mm-dd and I save the date in this format as a String. Now I have the String and I want to know how can I get yyyy, mm or dd in 3 different String.


If you know for sure that every single time it will be in that same format you can do a string split on that string, and get the values from the resulting array.

String date = "2011-06-15";

String[] dates = date.split("-");

String year = dates[0];
String month = dates[1];
String day = dates[2];

This won't work if your date ends up in a different format.


data = "2011-06-15";
String[] strings = data.split("-");
// strings[0] = "2011"
// strings[1] = "06"
// strings[2] = "15"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜