当前位置: 首页 > 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…...

HTML 语义化

目录 HTML 语义化HTML5 新特性HTML 语义化的好处语义化标签的使用场景最佳实践 HTML 语义化 HTML5 新特性 标准答案&#xff1a; 语义化标签&#xff1a; <header>&#xff1a;页头<nav>&#xff1a;导航<main>&#xff1a;主要内容<article>&#x…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

模型参数、模型存储精度、参数与显存

模型参数量衡量单位 M&#xff1a;百万&#xff08;Million&#xff09; B&#xff1a;十亿&#xff08;Billion&#xff09; 1 B 1000 M 1B 1000M 1B1000M 参数存储精度 模型参数是固定的&#xff0c;但是一个参数所表示多少字节不一定&#xff0c;需要看这个参数以什么…...

逻辑回归:给不确定性划界的分类大师

想象你是一名医生。面对患者的检查报告&#xff08;肿瘤大小、血液指标&#xff09;&#xff0c;你需要做出一个**决定性判断**&#xff1a;恶性还是良性&#xff1f;这种“非黑即白”的抉择&#xff0c;正是**逻辑回归&#xff08;Logistic Regression&#xff09;** 的战场&a…...

定时器任务——若依源码分析

分析util包下面的工具类schedule utils&#xff1a; ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类&#xff0c;封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz&#xff0c;先构建任务的 JobD…...

WEB3全栈开发——面试专业技能点P2智能合约开发(Solidity)

一、Solidity合约开发 下面是 Solidity 合约开发 的概念、代码示例及讲解&#xff0c;适合用作学习或写简历项目背景说明。 &#x1f9e0; 一、概念简介&#xff1a;Solidity 合约开发 Solidity 是一种专门为 以太坊&#xff08;Ethereum&#xff09;平台编写智能合约的高级编…...

GC1808高性能24位立体声音频ADC芯片解析

1. 芯片概述 GC1808是一款24位立体声音频模数转换器&#xff08;ADC&#xff09;&#xff0c;支持8kHz~96kHz采样率&#xff0c;集成Δ-Σ调制器、数字抗混叠滤波器和高通滤波器&#xff0c;适用于高保真音频采集场景。 2. 核心特性 高精度&#xff1a;24位分辨率&#xff0c…...

Linux离线(zip方式)安装docker

目录 基础信息操作系统信息docker信息 安装实例安装步骤示例 遇到的问题问题1&#xff1a;修改默认工作路径启动失败问题2 找不到对应组 基础信息 操作系统信息 OS版本&#xff1a;CentOS 7 64位 内核版本&#xff1a;3.10.0 相关命令&#xff1a; uname -rcat /etc/os-rele…...

Java + Spring Boot + Mybatis 实现批量插入

在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法&#xff1a;使用 MyBatis 的 <foreach> 标签和批处理模式&#xff08;ExecutorType.BATCH&#xff09;。 方法一&#xff1a;使用 XML 的 <foreach> 标签&#xff…...

Bean 作用域有哪些?如何答出技术深度?

导语&#xff1a; Spring 面试绕不开 Bean 的作用域问题&#xff0c;这是面试官考察候选人对 Spring 框架理解深度的常见方式。本文将围绕“Spring 中的 Bean 作用域”展开&#xff0c;结合典型面试题及实战场景&#xff0c;帮你厘清重点&#xff0c;打破模板式回答&#xff0c…...