This commit is contained in:
Looly
2021-03-18 21:16:14 +08:00
parent 825b5ea1b4
commit abdedf6822
9 changed files with 86 additions and 6 deletions

View File

@@ -544,6 +544,9 @@ public class BeanUtil {
* @since 5.2.4
*/
public static <T> T toBean(Object source, Class<T> clazz, CopyOptions options) {
if(null == source){
return null;
}
final T target = ReflectUtil.newInstanceIfPossible(clazz);
copyProperties(source, target, options);
return target;
@@ -559,6 +562,9 @@ public class BeanUtil {
* @return Bean
*/
public static <T> T toBean(Class<T> beanClass, ValueProvider<String> valueProvider, CopyOptions copyOptions) {
if (null == beanClass || null == valueProvider) {
return null;
}
return fillBean(ReflectUtil.newInstanceIfPossible(beanClass), valueProvider, copyOptions);
}
@@ -600,6 +606,9 @@ public class BeanUtil {
* @return Map
*/
public static Map<String, Object> beanToMap(Object bean, boolean isToUnderlineCase, boolean ignoreNullValue) {
if (null == bean) {
return null;
}
return beanToMap(bean, new LinkedHashMap<>(), isToUnderlineCase, ignoreNullValue);
}
@@ -614,7 +623,7 @@ public class BeanUtil {
* @since 3.2.3
*/
public static Map<String, Object> beanToMap(Object bean, Map<String, Object> targetMap, final boolean isToUnderlineCase, boolean ignoreNullValue) {
if (bean == null) {
if (null == bean) {
return null;
}
@@ -639,7 +648,7 @@ public class BeanUtil {
* @since 4.0.5
*/
public static Map<String, Object> beanToMap(Object bean, Map<String, Object> targetMap, boolean ignoreNullValue, Editor<String> keyEditor) {
if (bean == null) {
if (null == bean) {
return null;
}

View File

@@ -200,6 +200,15 @@ public class DatePattern {
*/
public static final FastDateFormat UTC_SIMPLE_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_PATTERN, TimeZone.getTimeZone("UTC"));
/**
* UTC时间yyyy-MM-dd'T'HH:mm:ss.SSS
*/
public static final String UTC_SIMPLE_MS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS";
/**
* UTC时间{@link FastDateFormat}yyyy-MM-dd'T'HH:mm:ss.SSS
*/
public static final FastDateFormat UTC_SIMPLE_MS_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_MS_PATTERN, TimeZone.getTimeZone("UTC"));
/**
* UTC时间yyyy-MM-dd'T'HH:mm:ss'Z'
*/

View File

@@ -836,6 +836,9 @@ public class DateUtil extends CalendarUtil {
} else if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 2) {
// 格式类似2018-09-13T05:34:31
return parse(utcString, DatePattern.UTC_SIMPLE_FORMAT);
} else if (StrUtil.contains(utcString, CharUtil.DOT)){
// 可能为: 2021-03-17T06:31:33.99
return parse(utcString, DatePattern.UTC_SIMPLE_MS_FORMAT);
}
}
// 没有更多匹配的时间格式

View File

@@ -550,6 +550,13 @@ public class DateUtilTest {
assert dt != null;
dateStr = dt.toString(simpleDateFormat);
Assert.assertEquals("2018-09-13 13:34:39.999", dateStr);
// 使用UTC时区
dateStr1 = "2018-09-13T13:34:39.99";
dt = DateUtil.parse(dateStr1);
assert dt != null;
dateStr = dt.toString();
Assert.assertEquals("2018-09-13 13:34:39", dateStr);
}
@Test