当前位置:网站首页>获取当前月份的第一天和最后一天,上个月的第一天和最后一天
获取当前月份的第一天和最后一天,上个月的第一天和最后一天
2022-06-26 06:05:00 【明明就很安静】
上个月第一天和最后一天
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TestController {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//获取当前月的第一天
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH,-1);
c.set(Calendar.DAY_OF_MONTH,1);
String dataStart = df.format(c.getTime());
//获取当月最后一天
Calendar c1 = Calendar.getInstance();
c1.add(Calendar.MONTH,-1);
c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
String dataEnd = df.format(c1.getTime());
}
}当月第一天和最后一天:
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TestController {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//获取当前月的第一天
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH,1);
String dataStart = df.format(c.getTime());
//获取当月最后一天
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
String dataEnd = df.format(c1.getTime());
}
}边栏推荐
猜你喜欢
随机推荐
实时数仓方案如何选型和构建
ES6的搭配环境
Easy to understand from the IDE, and then talk about the applet IDE
Implementation of third-party wechat authorized login for applet
tf.nn.top_k()
Data visualization practice: Data Visualization
numpy. log
Import export simple
Spark source code analysis (I): RDD collection data - partition data allocation
Matching environment of ES6
A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
Record how to modify the control across threads
06. talk about the difference and coding between -is and = = again
打印数字的位信息
Design and practice of low code real-time data warehouse construction system
Tencent WXG internship experience (has offered), I hope it will help you!
5 minutes to learn regular expressions
Basic construction of SSM framework
【群内问题学期汇总】初学者的部分参考问题
SQL Server视图









