将日历日期转换为字符串? [英] converting a calendar date to a string?
本文介绍了将日历日期转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让程序调用当前日期,添加30天,然后将该日期作为字符串。
I am trying to get the program to call up the current date, add 30 days to it, and then out put that date as a string.
// Set calendar for due date on invoice gui
Calendar cal = Calendar.getInstance();
// Add 30 days to the calendar for the due date
cal.add(Calendar.DATE, 30);
Date dueDate = cal.getTime();
dueDatestr = Calendar.toString(dueDate);
推荐答案
问题是?
如果您想格式化日期,建议您查看 java.text.SimpleDateFormat
,而不是使用 toString()
。您可以执行以下操作:
If you want to format your date, I suggest looking at java.text.SimpleDateFormat
instead of using toString()
. You can do something like:
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
dueDateStr = dateFormat.format(dueDate); // renders as 11/29/2009
这篇关于将日历日期转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文