无论是date还是datetime类型,都默认是YYYY-MM-DD hh:mm:ss的格式,如果只想保留日期,则有以下几种方式:
Date d = Date.today().toStartOfMonth();
System.debug( Datetime.newInstance(d.year(), d.month(), d.day()).format('yyyy-MM-dd') );
System.debug('Current date: ' + String.valueOf(Date.today().toStartOfMonth()).split(' ')[0]);
System.debug('Current date: ' + String.valueOf(Date.today()).removeEnd(' 00:00:00'));
参考资料:https://salesforce.stackexchange.com/questions/229075/how-to-remove-time-from-date