package com.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/*
*
*
*/
public class LastDay extends UDF {
public LastDay() {
}
public String evaluate(String thisdate) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
if (thisdate.length()==8)
format = new SimpleDateFormat("yyyyMMdd");
//获取当前月第一天:
Calendar c = Calendar.getInstance();
Date thisb=null;
try {
thisb=format.parse(thisdate);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(thisb);
c.add(Calendar.MONTH, 0);
// c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
// String first = format.format(c.getTime());
//
hive udf获取当前月最后一天
最新推荐文章于 2024-05-15 22:33:17 发布
![](https://img-home.csdnimg.cn/images/20240709112858.png)