我有用java代码编写的查询,这些查询用日期对某些行进行分组,其外观如下所示:
protected String groupBy() {
return " GROUP BY \"calendar_cte\".\"date\" ";
}返回的日期格式为:“time_date”:“2022-11-14”
我希望日期看起来像:Nov,14 2022,使用java中的springboot框架。
我该怎么做?我能用帕瑟吗?
发布于 2022-12-04 14:52:21
下面是一个例子
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateConverter {
public static String convert(String input) {
// Parse the input date string
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = inputFormat.parse(input);
// Use a SimpleDateFormat to convert the date to the desired output format
SimpleDateFormat outputFormat = new SimpleDateFormat("MMM, dd yyyy");
return outputFormat.format(date);
}
public static void main(String[] args) {
String output = convert("2022-11-14");
System.out.println(output); // prints "Nov, 14 2022"
}
}请注意,此代码使用java.text.SimpleDateFormat类解析和格式化日期,使用java.util.Date类表示日期本身。
这段代码只是一种可能的解决方案,可能还有其他方法来完成相同的任务。您可能希望修改此代码以满足您的特定需求。
https://stackoverflow.com/questions/74677055
复制相似问题