如何将数据从一种格式转换为另一种格式

| 我的日期格式为
yyyy-mm-dd
,并将此格式的日期另存为字符串。现在我有了String,我想知道如何在3个不同的String中得到
yyyy
mm
dd
。     
已邀请:
        如果您确定每次都将使用相同的格式,则可以对该字符串进行字符串拆分,然后从结果数组中获取值。
String date = \"2011-06-15\";

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

String year = dates[0];
String month = dates[1];
String day = dates[2];
如果您的日期以其他格式结尾,则此方法将无效。     
        
data = \"2011-06-15\";
String[] strings = data.split(\"-\");
// strings[0] = \"2011\"
// strings[1] = \"06\"
// strings[2] = \"15\"
    

要回复问题请先登录注册