Skip to content

Instantly share code, notes, and snippets.

@wander555
wander555 / getServerDate.js
Last active January 16, 2023 02:47
获取服务器的时间
function getServerDate() {
let date = null;
try {
let xhr = new XMLHttpRequest();
if (!xhr) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
xhr.open('HEAD', '/', false);
xhr.send(null);
const nowDate = xhr.getResponseHeader('Date');
@wander555
wander555 / stream.java
Last active November 10, 2022 07:07
java8 stream #stream
//去重
List<OnlineFactor> finalList = factorList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(x -> x.getName() + x.getCode()))), ArrayList::new));
@wander555
wander555 / es6.js
Last active January 3, 2023 03:17
JS关键代码 #es6 #js
//数组去重
const uniqueArr = (arr) => [...new Set(arr)];
console.log(uniqueArr(["前端","js","html","js","css","html"]));
//两日期之间相差的天数
const dayDiff = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000);
dayDiff(new Date("2021-10-21"), new Date("2022-02-12"))
//判断数组是否为空
const isNotEmpty = arr => Array.isArray(arr) && arr.length > 0;