将日历日期转换为字符串? [英] converting a calendar date to a string?

查看:436
本文介绍了将日历日期转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让程序调用当前日期,添加30天,然后将该日期作为字符串。

  //设置发票到期日的日历gui 
日历cal = Calendar.getInstance();

//为期限日期添加30天
cal.add(Calendar.DATE,30);
日期dueDate = cal.getTime();
dueDatestr = Calendar.toString(dueDate);


解决方案

问题是?
$ b

如果要格式化日期,建议您查看 java.text.SimpleDateFormat ,而不是使用 toString()。您可以执行以下操作:

  SimpleDateFormat dateFormat = new SimpleDateFormat(MM / dd / yyyy); 
dueDateStr = dateFormat.format(dueDate); //呈现为11/29/2009


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);

解决方案

And the question is?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆