开发者

How to transform the data from one format to another format

开发者 https://www.devze.com 2023-03-13 10:19 出处:网络
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

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

精彩评论

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