当前位置: 首页 > news >正文

鸿蒙实现年月日十分选择框,支持年月日、月日、日、年月日时分、时分切换

import DateTimeUtils from './DateTimeUtils';@CustomDialog
export default struct RQPickerDialog {controller: CustomDialogControllertitle: string = '这是标题'TAG: string = 'RQPickerDialog'// 0 - 日期类型(年月日)    1 - 时间类型(时分)    2 - 日期+时间类型    3 - 日期类型2(月日)    4-日期类型3(日)@State type: string = '4'private dateFormat: string = 'yyyy-MM-dd HH:mm'monthList: string[] = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];arr: number[] = [1, 3, 5, 7, 8, 10, 12] // 含有31天的月份@State dayList: string[] = []minimumDate: Date = new Date()maximumDate: Date = new Date()currentDate: Date = new Date()selectedTime: Date = new Date()@State @Watch('monthChange') selectedMonth: number = 0;selectedDay: number = 0;monthChange() {let year = this.currentDate.getFullYear()let dayOfMonth = this.arr.some(v => v === (this.selectedMonth + 1)) ? 31 : ((this.selectedMonth + 1) === 2 ? ((year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0)) ? 29 : 28) : 30)console.log(this.TAG, year + "-" + this.selectedMonth + "----有多少天 " + dayOfMonth)this.dayList = []for (let i = 0; i < dayOfMonth; i++) {this.dayList.push((i + 1) + "日")}console.log(this.TAG, this.dayList.join(','))}aboutToAppear() {this.minimumDate = new Date('1999-1-1 00:00');this.maximumDate = new Date('2124-1-1 00:00');this.currentDate = new Date('2016-2-27 10:00');this.selectedTime = this.currentDate;//月份本来就是从0开始的this.selectedMonth = this.currentDate.getMonth()this.selectedDay = this.currentDate.getDate() - 1console.log(this.TAG, this.selectedMonth + "----" + this.selectedDay)}build() {Column() {Text(this.title + this.type).fontSize(25).textAlign(TextAlign.Center).margin({ top: 10, bottom: 10 });Row() {if (this.type == '0') {DatePicker({start: new Date(this.minimumDate),end: new Date(this.maximumDate),selected: this.currentDate,}).lunar(false).onChange((value: DatePickerResult) => {this.currentDate.setFullYear(value.year, value.month, value.day)console.info('select current date is: ' + JSON.stringify(value))}).width('100%')} else if (this.type == '1') {TimePicker({ selected: this.selectedTime }).useMilitaryTime(true).onChange((date: TimePickerResult) => {this.currentDate.setHours(date.hour, date.minute)console.info('select current date is: ' + JSON.stringify(date))}).width('100%')} else if (this.type == '2') {DatePicker({start: new Date(this.minimumDate),end: new Date(this.maximumDate),selected: this.currentDate,}).lunar(false).onChange((value: DatePickerResult) => {this.currentDate.setFullYear(value.year, value.month, value.day)console.info('select current date is: ' + JSON.stringify(value))}).width('66%')TimePicker({ selected: this.selectedTime }).useMilitaryTime(true).onChange((date: TimePickerResult) => {this.currentDate.setHours(date.hour, date.minute)console.info('select current date is: ' + JSON.stringify(date))}).width('34%')} else if (this.type == '3') { //月日TextPicker({ range: this.monthList, selected: this.selectedMonth }).onChange((value: string, index: number) => {this.selectedMonth = indexlet month = ~~value.substring(0, value.length - 1)this.currentDate.setMonth(month - 1)console.info(this.TAG, 'month value is ' + value + "==" + month)}).width('50%')TextPicker({ range: this.dayList, selected: this.selectedDay }).onChange((value: string, index: number) => {this.selectedDay = indexlet day = ~~value.substring(0, value.length - 1)this.currentDate.setDate(day)console.info(this.TAG, 'day value is ' + value + "==" + day)}).width('50%')} else if (this.type == '4') { //日TextPicker({ range: this.dayList, selected: this.selectedDay }).onChange((value: string, index: number) => {this.selectedDay = indexlet day = ~~value.substring(0, value.length - 1)this.currentDate.setDate(day)console.info(this.TAG, 'day value is ' + value)}).width('100%')} else {DatePicker({start: new Date(this.minimumDate),end: new Date(this.maximumDate),selected: this.currentDate,}).lunar(false).onChange((value: DatePickerResult) => {this.currentDate.setFullYear(value.year, value.month, value.day)console.info('select current date is: ' + JSON.stringify(value))}).width('100%')}}Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {Button('取消', { type: ButtonType.Normal }).onClick(() => {// this.that.sendDialogEventToJsApi(this.dialogId, "cancel", { ok: false,//   dismissByClickBg: false,//   inputContent: '' })// this.that.closeH5Dialog(this.dialogId)this.controller.close()}).backgroundColor(0xffffff).fontColor(Color.Black).layoutWeight(1).height('100%')Divider().vertical(true).strokeWidth(1).color('#F1F3F5').opacity(1).height('100%')Button('确认', { type: ButtonType.Normal }).onClick(() => {this.controller.close()var formatResult = DateTimeUtils.dateFormat(this.currentDate, this.dateFormat)console.info(this.TAG, "select current date is: " + formatResult)}).backgroundColor(0xffffff).fontColor(Color.Blue).layoutWeight(1).height('100%')}.height(50)}}
}

日期格式化工具

/*timestamp: 13位时间戳 | new Date() | Date()console.log(dateFormat(1714528800000, 'YY-MM-DD HH:mm:ss'))format => YY:年,M:月,D:日,H:时,m:分钟,s:秒,SSS:毫秒
*/
export default class DateTimeUtils {static fixedTwo(value: number): string {return value < 10 ? '0' + value : String(value)}static dateFormat(timestamp: number | string | Date, format = 'yyyy-MM-dd HH:mm:ss'): string {var date = new Date(timestamp)var showTime = formatif (showTime.includes('SSS')) {const S = date.getMilliseconds()showTime = showTime.replace('SSS', '0'.repeat(3 - String(S).length) + S)}if (showTime.includes('yy')) {const Y = date.getFullYear()showTime = showTime.includes('yyyy') ? showTime.replace('yyyy', String(Y)) : showTime.replace('yy', String(Y).slice(2, 4))}if (showTime.includes('M')) {const M = date.getMonth() + 1showTime = showTime.includes('MM') ? showTime.replace('MM', this.fixedTwo(M)) : showTime.replace('M', String(M))}if (showTime.includes('d')) {const D = date.getDate()showTime = showTime.includes('dd') ? showTime.replace('dd', this.fixedTwo(D)) : showTime.replace('d', String(D))}if (showTime.includes('H')) {const H = date.getHours()showTime = showTime.includes('HH') ? showTime.replace('HH', this.fixedTwo(H)) : showTime.replace('H', String(H))}if (showTime.includes('m')) {var m = date.getMinutes()showTime = showTime.includes('mm') ? showTime.replace('mm', this.fixedTwo(m)) : showTime.replace('m', String(m))}if (showTime.includes('s')) {var s = date.getSeconds()showTime = showTime.includes('ss') ? showTime.replace('ss', this.fixedTwo(s)) : showTime.replace('s', String(s))}return showTime}
}

相关文章:

鸿蒙实现年月日十分选择框,支持年月日、月日、日、年月日时分、时分切换

import DateTimeUtils from ./DateTimeUtils;CustomDialog export default struct RQPickerDialog {controller: CustomDialogControllertitle: string 这是标题TAG: string RQPickerDialog// 0 - 日期类型&#xff08;年月日&#xff09; 1 - 时间类型&#xff08;时分&a…...

IntelliJ IDE 插件开发 | (三)消息通知与事件监听

系列文章 IntelliJ IDE 插件开发 |&#xff08;一&#xff09;快速入门IntelliJ IDE 插件开发 |&#xff08;二&#xff09;UI 界面与数据持久化IntelliJ IDE 插件开发 |&#xff08;三&#xff09;消息通知与事件监听 前言 在前两篇文章中讲解了关于插件开发的基础知识&…...

VUE小知识点

Vue 是一款用于构建用户界面的 JavaScript 框架。它基于标准 HTML、CSS 和 JavaScript 构建&#xff0c;并提供了一套声明式的、组件化的编程模型&#xff0c;帮助你高效地开发用户界面。 Vue 的主要作用是帮助开发者构建现代 Web 应用程序。它允许前端开发人员专注于应用程序…...

深入了解常见的应用层网络协议

目录 1. HTTP协议 1.1. 工作原理 1.2. 应用场景 1.3. 安全性考虑 2. SMTP协议 2.1. 工作原理 2.2. 应用场景 2.3. 安全性考虑 3. FTP协议 3.1. 工作原理 3.2. 应用场景 3.3. 安全性考虑 4. DNS协议 4.1. 工作原理 4.2. 应用场景 4.3. 安全性考虑 5. 安全性考虑…...

网络爬虫 多任务采集

一、JSON文件存储 JSON&#xff0c;全称为 JavaScript 0bject Notation,也就是JavaSript 对象标记&#xff0c;它通过对象和数组的组合来表示数据&#xff0c;构造简洁但是结构化程度非常高&#xff0c;是一种轻量级的数据交换格式。本节中&#xff0c;我们就来了解如何利用 P…...

真实并发编程问题-1.钉钉面试题

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是爱吃芝士的土豆倪&#xff0c;24届校招生Java选手&#xff0c;很高兴认识大家&#x1f4d5;系列专栏&#xff1a;Spring源码、JUC源码、Kafka原理、分布式技术原理、数据库技术&#x1f525;如果感觉博主的文章还不错的…...

基于vue+element-plus+echarts制作动态绘图页面(柱状图,饼图和折线图)

前言 我们知道echarts是一个非常强大的绘图库&#xff0c;基于这个库&#xff0c;我们可以绘制出精美的图表。对于一张图来说&#xff0c;其实比较重要的就是配置项&#xff0c;填入不同的配置内容就可以呈现出不同的效果。 当然配置项中除了样式之外&#xff0c;最重要的就是…...

2312llvm,02前端

前端 编译器前端,在生成目标相关代码前,把源码变换为编译器的中间表示.因为语言有独特语法和语义,所以一般,前端只处理一个语言或一组类似语言. 比如Clang,处理C,C,objective-C源码. 介绍Clang Clang项目是C,C,Objective-C官方的LLVM前端.Clang的官方网站在此. 实际编译器(…...

【MATLAB源码-第101期】基于matlab的蝙蝠优化算BA)机器人栅格路径规划,输出做短路径图和适应度曲线。

操作环境&#xff1a; MATLAB 2022a 1、算法描述 蝙蝠算法&#xff08;BA&#xff09;是一种基于群体智能的优化算法&#xff0c;灵感来源于蝙蝠捕食时的回声定位行为。这种算法模拟蝙蝠使用回声定位来探测猎物、避开障碍物的能力。在蝙蝠算法中&#xff0c;每只虚拟蝙蝠代表…...

【数据结构】二叉树的模拟实现

前言:前面我们学习了堆的模拟实现&#xff0c;今天我们来进一步学习二叉树&#xff0c;当然了内容肯定是越来越难的&#xff0c;各位我们一起努力&#xff01; &#x1f496; 博主CSDN主页:卫卫卫的个人主页 &#x1f49e; &#x1f449; 专栏分类:数据结构 &#x1f448; &…...

open3d bug:pcd转txt前后位姿发生改变

1、open3d bug&#xff1a;pcd转txt前后位姿发生改变 open3d会对原有结果进行一个微小位姿变换 import open3d as o3d import numpy as np# 读取PCD点云文件 pcd o3d.io.read_point_cloud(/newdisk/darren_pty/zoom_centered_s2.pcd)# 获取点云坐标 points pcd.points# 指定…...

持续集成交付CICD:Jenkins使用GitLab共享库实现基于Ansible的CD流水线部署前后端应用

目录 一、实验 1.部署Ansible自动化运维工具 2.K8S 节点安装nginx 3.Jenkins使用GitLab共享库实现基于Ansible的CD流水线部署前后端应用 二、问题 1.ansible安装报错 2.ansible远程ping失败 3. Jenkins流水线通过ansible命令直接ping多台机器的网络状态报错 一、实验 …...

OpenAI 疑似正在进行 GPT-4.5 灰度测试!

‍ 大家好&#xff0c;我是二狗。 今天&#xff0c;有网友爆料OpenAI疑似正在进行GPT-4.5灰度测试&#xff01; 当网友询问ChatGPT API调用查询模型的确切名称是什么时&#xff1f; ChatGPT的回答竟然是 gpt-4.5-turbo。 也有网友测试之后发现仍然是GPT-4模型。 这是有网友指…...

DC-6靶场

DC-6靶场下载&#xff1a; https://www.five86.com/downloads/DC-6.zip 下载后解压会有一个DC-3.ova文件&#xff0c;直接在vm虚拟机点击左上角打开-->文件-->选中这个.ova文件就能创建靶场&#xff0c;kali和靶机都调整至NAT模式&#xff0c;即可开始渗透 首先进行主…...

单片机应用实例:LED显示电脑电子钟

本例介绍一种用LED制作的电脑电子钟&#xff08;电脑万年历&#xff09;。其制作完成装潢后的照片如下图&#xff1a; 上图中&#xff0c;年、月、日及时间选用的是1.2寸共阳数码管&#xff0c;星期选用的是2.3寸数码管&#xff0c;温度选用的是0.5寸数码管&#xff0c;也可根据…...

会议剪影 | 思腾合力受邀出席首届CCF数字医学学术年会

首届CCF数字医学学术年会&#xff08;CCF Digital Medicine Symposium&#xff0c;DMS&#xff09;于2023年12月15日-17日在苏州CCF业务总部召开。这次会议的成功召开&#xff0c;标志着数字医学领域进入了一个新的时代&#xff0c;计算机技术和人工智能在医学领域的应用和发展…...

node.js mongoose中间件(middleware)

目录 简介 定义模型 注册中间件 创建doc实例&#xff0c;并进行增删改查 方法名和注册的中间件名相匹配 执行结果 分析 错误处理中间件 手动抛出错误 注意点 简介 在mongoose中&#xff0c;中间件是一种允许在执行数据库操作前&#xff08;pre&#xff09;或后&…...

[Toolschain cpp ros cmakelist python vscode] 记录写每次项目重复的设置和配置 不断更新

写在前面 用以前的设置&#xff0c;快速配置项目&#xff0c;以防长久不用忘记&#xff0c;部分资料在资源文件里还没有整理 outline cmakelist 复用vscode 找到头文件vscode debug现有代码直接关联远端gitros杂记repo 杂记glog杂记 cmakelist 复用 包含了根据系统路径找库…...

【每日OJ—有效的括号(栈)】

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言 1、有效的括号题目&#xff1a; 1.1方法讲解&#xff1a; 1.2代码实现&#xff1a; 总结 前言 世上有两种耀眼的光芒&#xff0c;一种是正在升起的太阳&#…...

.gitignore和git lfs学习

The ninth day——12.18 1. .gitignore 忽略规则优先级 从命令行中读取可用的忽略规则当前目录定义的规则父级目录定义的规则&#xff0c;依次递推$GIT_DIR/info/exclude 文件中定义的规则core.excludesfile中定义的全局规则 忽略规则匹配语法 空格不匹配任意文件&#xff…...

linux arm系统烧录

1、打开瑞芯微程序 2、按住linux arm 的 recover按键 插入电源 3、当瑞芯微检测到有设备 4、松开recover按键 5、选择升级固件 6、点击固件选择本地刷机的linux arm 镜像 7、点击升级 &#xff08;忘了有没有这步了 估计有&#xff09; 刷机程序 和 镜像 就不提供了。要刷的时…...

1.3 VSCode安装与环境配置

进入网址Visual Studio Code - Code Editing. Redefined下载.deb文件&#xff0c;然后打开终端&#xff0c;进入下载文件夹&#xff0c;键入命令 sudo dpkg -i code_1.100.3-1748872405_amd64.deb 在终端键入命令code即启动vscode 需要安装插件列表 1.Chinese简化 2.ros …...

DBAPI如何优雅的获取单条数据

API如何优雅的获取单条数据 案例一 对于查询类API&#xff0c;查询的是单条数据&#xff0c;比如根据主键ID查询用户信息&#xff0c;sql如下&#xff1a; select id, name, age from user where id #{id}API默认返回的数据格式是多条的&#xff0c;如下&#xff1a; {&qu…...

是否存在路径(FIFOBB算法)

题目描述 一个具有 n 个顶点e条边的无向图&#xff0c;该图顶点的编号依次为0到n-1且不存在顶点与自身相连的边。请使用FIFOBB算法编写程序&#xff0c;确定是否存在从顶点 source到顶点 destination的路径。 输入 第一行两个整数&#xff0c;分别表示n 和 e 的值&#xff08;1…...

人机融合智能 | “人智交互”跨学科新领域

本文系统地提出基于“以人为中心AI(HCAI)”理念的人-人工智能交互(人智交互)这一跨学科新领域及框架,定义人智交互领域的理念、基本理论和关键问题、方法、开发流程和参与团队等,阐述提出人智交互新领域的意义。然后,提出人智交互研究的三种新范式取向以及它们的意义。最后,总结…...

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的“no matching...“系列算法协商失败问题

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的"no matching..."系列算法协商失败问题 摘要&#xff1a; 近期&#xff0c;在使用较新版本的OpenSSH客户端连接老旧SSH服务器时&#xff0c;会遇到 "no matching key exchange method found"​, "n…...

什么是VR全景技术

VR全景技术&#xff0c;全称为虚拟现实全景技术&#xff0c;是通过计算机图像模拟生成三维空间中的虚拟世界&#xff0c;使用户能够在该虚拟世界中进行全方位、无死角的观察和交互的技术。VR全景技术模拟人在真实空间中的视觉体验&#xff0c;结合图文、3D、音视频等多媒体元素…...

C++实现分布式网络通信框架RPC(2)——rpc发布端

有了上篇文章的项目的基本知识的了解&#xff0c;现在我们就开始构建项目。 目录 一、构建工程目录 二、本地服务发布成RPC服务 2.1理解RPC发布 2.2实现 三、Mprpc框架的基础类设计 3.1框架的初始化类 MprpcApplication 代码实现 3.2读取配置文件类 MprpcConfig 代码实现…...

基于江科大stm32屏幕驱动,实现OLED多级菜单(动画效果),结构体链表实现(独创源码)

引言 在嵌入式系统中&#xff0c;用户界面的设计往往直接影响到用户体验。本文将以STM32微控制器和OLED显示屏为例&#xff0c;介绍如何实现一个多级菜单系统。该系统支持用户通过按键导航菜单&#xff0c;执行相应操作&#xff0c;并提供平滑的滚动动画效果。 本文设计了一个…...

yaml读取写入常见错误 (‘cannot represent an object‘, 117)

错误一&#xff1a;yaml.representer.RepresenterError: (‘cannot represent an object’, 117) 出现这个问题一直没找到原因&#xff0c;后面把yaml.safe_dump直接替换成yaml.dump&#xff0c;确实能保存&#xff0c;但出现乱码&#xff1a; 放弃yaml.dump&#xff0c;又切…...