Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date GROOVY中如何从日期格式中删除时间_Date_Groovy - Fatal编程技术网

Date GROOVY中如何从日期格式中删除时间

Date GROOVY中如何从日期格式中删除时间,date,groovy,Date,Groovy,我有这个 def day1 =1 def month1 = 10 def year1 = 111 render "a" def date1 = new Date(year1 ,month1, day1); 输出是 Sat Oct 01 00:00:00 PKT 2011 日期可以,但我可以删除此时间格式和国家符号,即01 00:00:00 PKT吗 谢谢您不能删除它,时区和时间始终是日期对象的一部分。不过,您可以选择日期部分 groovy&g

我有这个

    def day1 =1
    def month1 = 10
    def year1 = 111
    render "a"

    def date1 = new Date(year1 ,month1, day1);
输出是

    Sat Oct 01 00:00:00 PKT 2011
日期可以,但我可以删除此时间格式和国家符号,即01 00:00:00 PKT吗


谢谢

您不能删除它,时区和时间始终是日期对象的一部分。不过,您可以选择日期部分

groovy> def day1 =1 
groovy> def month1 = 10 
groovy> def year1 = 111 
groovy> def date1 = new Date(year1 ,month1, day1); 
groovy> print(date1.getDateString()) 
groovy> print("\n") 
groovy> print(date1.format("yyyy-MM-dd")) 

11/1/11
2011-11-01

正如人们一直告诉你的那样,你不应该使用日期构造函数,因为它已经被弃用了

更好的Groovy示例是:

def day1 =1
def month1 = 10
def year1 = 2011

String dateStr = Calendar.instance.with {
  set( year1, month1, day1 )
  format( 'yyyy-MM-dd' )
}
还有一个使用系统区域设置中的日期格式的