kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

JS 获取当前的日期和时间

https://www.jyshare.com/codedemo/7672/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var today = new Date();

//日期
var DD = String(today.getDate()).padStart(2, '0');    // 获取日
var MM = String(today.getMonth() + 1).padStart(2, '0');   // 获取月份,1 月为 0
var yyyy = today.getFullYear();               // 获取年

// 时间
hh =  String(today.getHours()).padStart(2, '0');  // 获取当前小时数(0-23)
mm = String(today.getMinutes()).padStart(2, '0'); // 获取当前分钟数(0-59)
ss = String(today.getSeconds()).padStart(2, '0'); // 获取当前秒数(0-59)

today = yyyy + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss;
document.write(today);

GPS 两点距离

https://www.cnblogs.com/thinkquan/p/3925199.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function rad($d)
{
	return $d * 3.1415926535898 / 180.0;
}

function GetDistance($lat1, $lng1, $lat2, $lng2)
{
	$EARTH_RADIUS = 6378.137;

	$radLat1 = $this->rad($lat1);
	$radLat2 = $this->rad($lat2);
	$a = $radLat1 - $radLat2;

	$b = $this->rad($lng1) - $this->rad($lng2);

	$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));
	$s = $s *$EARTH_RADIUS;
	$s = round($s * 1000);
	return $s;
}

GetDistance(26.000000, 118.000000, 25.000000, 117.000000);

JS获取当前地理位置

https://www.jb51.net/article/58654.htm

https://www.jb51.net/javascript/304171feq.htm

https://blog.csdn.net/weixin_53791978/article/details/132012586

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var getLocation = function (successFunc, errorFunc) { //successFunc获取定位成功回调函数,errorFunc获取定位失败回调
	//默认城市
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(function (position) {
			var lat = position.coords.latitude;
			var lon = position.coords.longitude;
		},
		function (error) {
			switch (error.code) {
				case 1:
					alert("位置服务被拒绝。");
					break;
				case 2:
					alert("暂时获取不到位置信息。");
					break;
				case 3:
					alert("获取位置信息超时。");
					break;
				default:
					alert("未知错误。");
					break;
			}
		});
	} else {
		alert("你的浏览器不支持获取地理位置信息。");
		if (errorFunc != undefined)
			errorFunc("你的浏览器不支持获取地理位置信息。");
	}
};