mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -12,6 +12,7 @@ import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -701,6 +702,16 @@ public class DateTime extends Date {
|
||||
return new java.sql.Date(getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 {@link LocalDateTime}
|
||||
*
|
||||
* @return {@link LocalDateTime}
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public LocalDateTime toLocalDateTime() {
|
||||
return LocalDateTimeUtil.of(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算相差时长
|
||||
*
|
||||
|
@@ -18,6 +18,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -4338,7 +4339,21 @@ public class CharSequenceUtil {
|
||||
* @return 给定字符串的所有字符是否都一样
|
||||
* @since 5.7.3
|
||||
*/
|
||||
public static boolean isCharEquals(String str) {
|
||||
return isBlank(str.replace(str.charAt(0), CharUtil.SPACE));
|
||||
public static boolean isCharEquals(CharSequence str) {
|
||||
Assert.notEmpty(str, "Str to check must be not empty!");
|
||||
return count(str, str.charAt(0)) == str.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串归一化处理,如 "Á" 可以使用 "u00C1"或 "u0041u0301"表示,实际测试中两个字符串并不equals<br>
|
||||
* 因此使用此方法归一为一种表示形式,默认按照W3C通常建议的,在NFC中交换文本。
|
||||
*
|
||||
* @param str 归一化的字符串
|
||||
* @return 归一化后的字符串
|
||||
* @see Normalizer#normalize(CharSequence, Normalizer.Form)
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public static String normalize(CharSequence str) {
|
||||
return Normalizer.normalize(str, Normalizer.Form.NFC);
|
||||
}
|
||||
}
|
||||
|
@@ -33,5 +33,19 @@ public class CharSequenceUtilTest {
|
||||
Assert.assertEquals( str + " is Good", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeTest(){
|
||||
// https://blog.csdn.net/oscar999/article/details/105326270
|
||||
|
||||
String str1 = "\u00C1";
|
||||
String str2 = "\u0041\u0301";
|
||||
|
||||
Assert.assertNotEquals(str1, str2);
|
||||
|
||||
str1 = CharSequenceUtil.normalize(str1);
|
||||
str2 = CharSequenceUtil.normalize(str2);
|
||||
Assert.assertEquals(str1, str2);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------ remove
|
||||
}
|
||||
|
Reference in New Issue
Block a user