From 242975d17a90cb2c2d1f7325c02cf7a40a508f52 Mon Sep 17 00:00:00 2001 From: 20220016 <17777770016@qq.com> Date: Thu, 11 Jul 2024 19:08:24 +0800 Subject: [PATCH] ADD file via upload --- DateFunction.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 DateFunction.java diff --git a/DateFunction.java b/DateFunction.java new file mode 100644 index 0000000..d90a148 --- /dev/null +++ b/DateFunction.java @@ -0,0 +1,31 @@ +package com.sen.api.functions; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.sen.api.utils.StringUtil; + +public class DateFunction implements Function{ + + @Override + public String execute(String[] args) { + if (args.length == 0 ||StringUtil.isEmpty(args[0])) { + return String.format("%s", new Date().getTime()); + } else { + return getCurrentDate("yyyy-MM-dd"); + } + } + + private String getCurrentDate(String pattern) { + SimpleDateFormat format = new SimpleDateFormat(pattern); + String str = format.format(new Date()); + return str; + } + + @Override + public String getReferenceKey() { + // TODO Auto-generated method stub + return "date"; + } + +}