Skip to content

Commit

Permalink
Merge pull request #23 from guoshiqiufeng/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
guoshiqiufeng authored Mar 3, 2022
2 parents 7c50bdc + 93368b5 commit 5580e4b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# kernel
[![Maven central](https://maven-badges.herokuapp.com/maven-central/com.gitee.fubluesky.kernel/kernel/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.gitee.fubluesky.kernel/kernel)
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
[![Maven central](https://img.shields.io/maven-central/v/com.gitee.fubluesky.kernel/kernel.svg?style=flat-square)](https://search.maven.org/search?q=g:com.gitee.fubluesky.kernel%20AND%20a:kernel)
[![License](https://img.shields.io/:license-apache-brightgreen.svg?style=flat-square)](http://www.apache.org/licenses/LICENSE-2.0.html)
#### 介绍
内核框架
#### 依赖
Expand Down
3 changes: 3 additions & 0 deletions kernel-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@

随机数工具类:产生随机数字

- `LocalDateTimeUtils`

LocalDateTime 工具类 可获取 获取年开始时间、结束时间 获取月开始时间、结束时间 获取日开始时间、结束时间
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
*
* Copyright 2021 fubluesky.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.gitee.fubluesky.kernel.core.util;

import lombok.experimental.UtilityClass;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;

/**
* LocalDateTime 工具类
* @author yanghq
* @version 1.0
* @since 2022-03-02 13:11
*/
@UtilityClass
public class LocalDateTimeUtils {

/**
* 获取年开始时间
* @param date 时间
* @return 年开始时间
*/
public LocalDateTime beginOfYear(LocalDateTime date) {
return LocalDateTime.of(LocalDate.from(date.with(TemporalAdjusters.firstDayOfYear())), LocalTime.MIN);
}


/**
* 获取年结束时间
* @param date 时间
* @return 年结束时间
*/
public LocalDateTime endOfYear(LocalDateTime date) {
return LocalDateTime.of(LocalDate.from(date.with(TemporalAdjusters.lastDayOfYear())), LocalTime.MAX);
}

/**
* 获取月开始时间
* @param date 时间
* @return 月开始时间
*/
public static LocalDateTime beginOfMonth(LocalDateTime date) {
return LocalDateTime.of(LocalDate.from(date.with(TemporalAdjusters.firstDayOfMonth())), LocalTime.MIN);
}

/**
* 获取月结束时间
* @param date 时间
* @return 月结束时间
*/
public static LocalDateTime endOfMonth(LocalDateTime date) {
return LocalDateTime.of(LocalDate.from(date.with(TemporalAdjusters.lastDayOfMonth())), LocalTime.MAX);
}

/**
* 获取日开始时间
* @param date 时间
* @return 日开始时间
*/
public static LocalDateTime beginOfDay(LocalDateTime date) {
return date.with(LocalTime.MIN);
}

/**
* 获取日结束时间
* @param date 时间
* @return 日结束时间
*/
public static LocalDateTime endOfDay(LocalDateTime date) {
return date.with(LocalTime.MAX);
}
}

0 comments on commit 5580e4b

Please sign in to comment.