package com.zy.asrs.controller; import com.core.common.Cools; import com.core.common.R; import com.zy.common.service.CommonService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Calendar; import java.util.Date; /** * Created by vincent on 2020/11/16 */ @RestController @RequestMapping("/monitor") public class MonitorController { private static final String[] WEEK = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; /** * 获取当前时间 */ @GetMapping("/date") public R monitorDate() { Date now = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(now); return R.ok( Cools.add("year", calendar.get(Calendar.YEAR)) .add("month", CommonService.zerofill(String.valueOf(calendar.get(Calendar.MONTH)+1), 2)) .add("day", CommonService.zerofill(String.valueOf(calendar.get(Calendar.DATE)), 2)) .add("hour", CommonService.zerofill(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)), 2)) .add("minute", CommonService.zerofill(String.valueOf(calendar.get(Calendar.MINUTE)), 2)) .add("second", CommonService.zerofill(String.valueOf(calendar.get(Calendar.SECOND)) , 2)) .add("week", WEEK[calendar.get(Calendar.DAY_OF_WEEK)-1]) ); } }