linux21-日期时间

news/2024/10/11 2:31:04

linux21-日期时间


  • date 查看系统时间

  • 更改/etc/localtime 修改时区

  • ntp自动校准时区


date

查看系统时间

date [-d] [+格式化字符串]
-d, 通过给定的字符串显示日期, 一般用于日期计算, 支持以下时间标记
  • year 年

  • month 月

  • day 天

  • hour 小时

  • minute 分钟

  • second 秒

格式化字符串
  • %Y 年

  • %y 年份后两位数字

  • %m 月份

  • %d 日

  • %H 小时

  • %M 分钟

  • %S 秒

  • %s 自1970-01-01 00:00:00 UTC到现在的秒数


直接查看系统时间

date

通过格式化字符串自定义显示格式

# 2024-05-04
date +%Y-%m-%d

# 2024年5月4日16:55:58
date +%Y年%m月%d日%H:%M:%S


通过-d选项进行日期计算

date -d "+1 day" +%Y年%m月%d日%H:%M:%S

date -d "-4 year" +%Y年%m月%d日%H:%M:%S

可以写入多个参数

date -d "-3 year +2 month +14day" +%Y年%m月%d日%H:%M:%S


修改时区

删除系统的localtime

sudo rm -f /etc/localtime

将墨尔本时间软链接到localtime,修改时区

sudo ln -s /usr/share/zoneinfo/Australia/Melbourne /etc/localtime

查看时间

date

删除系统的localtime

sudo rm -f /etc/localtime

将上海时间软链接至localtime, 修改时区

sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

查看时间

date


自动校准时间

ntp服务能够定期联网校准系统时间

通过apt (CentOS为yum) 下载ntp (ntpd)

apt install -y ntp

启动ntp服务,并设置为开机自启

# 启动服务
systemctl ntp start
# 开机自启动
systemctl ntp enable

通过连接ntp服务手动校准, 需要root权限和网络

ntpd -u ntp.aliyun.com

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/27508.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

npm创建项目

创建项目创建项目目录 首先新建一个文件夹,这里存放着我们的项目。创建项目文件 这里不使用任何项目模板,相当于使用空模板。 进入这个文件夹,再cmd中运行npm init。 然后按照提示输入package name,项目名等等。每输入一个就回车。完成之后目录下会出现一个package.json项目…

springboot为什么要用延迟导入?

Spring Boot使用了多种方式来实现自动配置,其中DeferredImportSelector接口是这些机制之一。 DeferredImportSelector是ImportSelector的一个扩展,它允许延迟导入配置类直到所有@Configuration类都被处理完毕。这对于某些自动配置类需要在应用程序上下文的创建过程中的后期阶…

深入学习和理解Django视图层:处理请求与响应

title: 深入学习和理解Django视图层:处理请求与响应 date: 2024/5/4 17:47:55 updated: 2024/5/4 17:47:55 categories:后端开发tags:Django 请求处理 响应生成 模板渲染 表单处理 中间件 异常处理第一章:Django框架概述 1.1 什么是Django? Django是一个高级的Python Web框架…

常见的排序算法

常见的排序算法 目录一、冒泡排序(Bubble Sort)二、插入排序(Insert Sort)三、选择排序 (Selection Sort)四、希尔排序(Shell Sort)五、快速排序(Quick Sort)六、堆排序(Heap Sort)七、归并排序(Merge Sort)八、计数排序(Count Sort()九、桶排序 (Bucket Sort)十、基数排序…

K8S 创建Spring-boot项目并进行项目启动与访问

##Spring-boot 的helloworld 项目package com.example.demo;import java.time.LocalDateTime; import java.time.format.DateTimeFormatter;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; imp…

狂神spring学习笔记

1. Spring 1. 简介 一个融合器,一个简化开发的框架 spring官网 github地址 2. Maven坐标 <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency><groupId>org.springframework</groupId><artifactId>sp…

2024-05-04 如何为antd的table设置序号

给columns加多一列即可:const columns = [{title: "序号",key: "index",render: (_, record, index) => index + 1,},...]如图:

Multisim14--软件简介及安装教程(内含安装包)

安装包见文章末尾一、软件简介 Multisim是美国国家仪器(NI)有限公司推出的以Windows为基础的仿真工具,适用于板级的模拟/数字电路板的设计工作。它包含了电路原理图的图形输入、电路硬件描述语言输入方式,具有丰富的仿真分析能力。工程师们可以使用Multisim交互式地搭建电路…