js,uniapp,vue类似于微信和qq时间间隔显示

这个JavaScript函数用于将时间戳转换为易于阅读的日期和时间格式。根据时间戳与当前时间的差距,它会返回年-月-日、月-日-时:分或当天的时:分格式。代码适用于毫秒级时间戳,适用于前端或后端开发中的时间显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用方法前提:时间必须是毫秒为单位的时间戳,如果不是请自行修改代码

timeFliter(timer){
				let sendTime = timer 
				let timeData = new Date(timer)
				let nowData = new Date().getTime() //获取现在的时间
				let str = '';
				let yesterday = new Date(new Date().toLocaleDateString()).getTime() - 1000 //获取昨天凌晨23:59时间
				 if((yesterday-sendTime)>31536000000){//年-月-日 
					str = new Date(timeData).getFullYear()+'-' + (new Date(timeData).getMonth()+1) + '-' + new Date(timeData).getDate()
				}else if((yesterday-sendTime ) > 86400000 && (yesterday-sendTime) < 31536000000){//月 日 时分
						str = (new Date(timeData).getMonth()+1) + '-' + new Date(timeData).getDate() + ' '+ new Date(timeData).getHours() + ':' + new Date(timeData).getMinutes()
				}else if((yesterday-sendTime)<86400000 && (yesterday-sendTime) > 0){//月 日 时分
					str = (new Date(timeData).getMonth()+1) + '-' + new Date(timeData).getDate() + ' '+ new Date(timeData).getHours() + ':' + new Date(timeData).getMinutes()
				}else{//当天
					str = new Date(timeData).getHours() + ':' + new Date(timeData).getMinutes()
				}
return str
}

使用方法:

可在js或者html中使用

<div>{{1652692614834|timeFliter}}</div>
var updateTime = this.timeFliter(1652692614834)

注意:此代码中的str =xxxxxxxxx这段代码没有经过测试,请自行书写,但是if判断应该没问题

其中的的两个else if 应该可以合并,本人因为效果出来了就没有去优化,有大佬优化测试之后,可以告知一下,谢谢

UniApp 中使用 Vue3 进行微信好友分享功能,并携带自定义参数,可以借助微信JSSDK 来实现。首先,你需要安装微信官方提供的 `uni-share` 插件,可以在项目配置文件 `config.json` 的 `framework` 部分添加: ```json { "framework": { "plugins": { "uni-share": {} } }, // ... } ``` 然后,在需要分享的页面,引入并初始化 `uni-share` 组件,设置分享内容参数: ```html <template> <view> <uni-share :title="shareTitle" :link="shareLink" :description="shareDescription"> <!-- 自定义参数 --> <block v-if="hasCustomParams"> <uni-share-action name="sessionFromWechatFriend" data={{ customParams }} /> </block> </uni-share> </view> </template> <script setup> import { onMounted } from 'vue'; import { share } from '@dcloudio/uni-share'; const shareTitle = '我的分享标题'; const shareLink = 'https://example.com/share'; const shareDescription = '这是一段描述信息'; let hasCustomParams = true; // 根据需求设置是否携带自定义参数 let customParams = { key1: 'value1', key2: 'value2' }; // 这里填写你想要传递给微信好友的具体参数 onMounted(() => { share({ title: shareTitle, link: shareLink, desc: shareDescription, scene: 'friend', // 表示分享到微信好友 success: () => console.log('分享成功'), fail: (res) => console.error(res) }); }); </script> ``` 在这里,`customParams` 对象是你自定义的键值对,会在用户点击分享按钮时作为参数传递给接收方。当`hasCustomParams`为真时,才会显示带有自定义参数的分享选项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值