Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
shishuangxi
2024-02-02 17:21:42 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5711d2bc4d74692996a56418c34861c81cc0a9cc
5711d2bc
1 parent
11ae1014
增加文章发布时间工具转换
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
17 deletions
PeopleDaily_Harmony/wdComponent/src/main/ets/components/view/TitleAbbrComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/view/TitleAllComponent.ets
PeopleDaily_Harmony/wdKit/src/main/ets/utils/DateTimeUtils.ts
PeopleDaily_Harmony/wdComponent/src/main/ets/components/view/TitleAbbrComponent.ets
View file @
5711d2b
...
...
@@ -6,12 +6,12 @@ import { DateTimeUtils } from 'wdKit'
@Component
export struct TitleAbbrComponent {
@State compDTO: CompDTO = {} as CompDTO
@State @Watch('isPoint') source:boolean=false;//来源是否为空 publishTime 字段是否为空
@State isPo:number=Visibility.Visible;
@State @Watch('isPoint') source: boolean = false; //来源是否为空 publishTime 字段是否为空
@State isPo: number = Visibility.Visible;
isPoint(){
if(this.source){
this.isPo=Visibility.None
isPoint() {
if (this.source) {
this.isPo = Visibility.None
}
}
...
...
@@ -39,7 +39,7 @@ export struct TitleAbbrComponent {
.height(16)
.visibility(this.isPo)
Text(DateTimeUtils.
formatDat
e(Number.parseFloat(this.compDTO.operDataList[0].publishTime)))
Text(DateTimeUtils.
getCommentTim
e(Number.parseFloat(this.compDTO.operDataList[0].publishTime)))
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.fontWeight(400)
...
...
@@ -59,12 +59,12 @@ export struct TitleAbbrComponent {
.margin({ bottom: 8 })
}
aboutToAppear(){
if(this.compDTO.operDataList[0].source==""){
this.source=true;
aboutToAppear() {
if (this.compDTO.operDataList[0].source == "") {
this.source = true;
}
if(this.compDTO.operDataList[0].publishTime==""){
this.source=true;
if (this.compDTO.operDataList[0].publishTime == "") {
this.source = true;
}
}
}
\ No newline at end of file
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/components/view/TitleAllComponent.ets
View file @
5711d2b
...
...
@@ -7,12 +7,12 @@ import { Logger } from 'wdKit/src/main/ets/utils/Logger'
@Component
export struct TitleAllComponent {
@State compDTO: CompDTO = {} as CompDTO
@State @Watch('isPoint') source:boolean=false;//来源是否为空 publishTime 字段是否为空
@State isPo:number=Visibility.Visible;
@State @Watch('isPoint') source: boolean = false; //来源是否为空 publishTime 字段是否为空
@State isPo: number = Visibility.Visible;
isPoint(){
if(this.source){
this.isPo=Visibility.None
isPoint() {
if (this.source) {
this.isPo = Visibility.None
}
}
...
...
@@ -38,7 +38,7 @@ export struct TitleAllComponent {
.height(16)
.visibility(this.isPo)
Text(DateTimeUtils.
formatDat
e(Number.parseFloat(this.compDTO.operDataList[0].publishTime)))
Text(DateTimeUtils.
getCommentTim
e(Number.parseFloat(this.compDTO.operDataList[0].publishTime)))
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.fontWeight(400)
...
...
PeopleDaily_Harmony/wdKit/src/main/ets/utils/DateTimeUtils.ts
View file @
5711d2b
...
...
@@ -50,6 +50,7 @@ export class DateTimeUtils {
static
readonly
PATTERN_DATE_CN
:
string
=
'yyyy年MM月dd日'
;
// 日期中包含包含中文年月日
static
readonly
PATTERN_DATE_SLASH_WITHOUT_YEAR
:
string
=
'MM/dd'
;
// 日期中不包含年份
static
readonly
PATTERN_DATE_CN_WITHOUT_YEAR
:
string
=
'MM月dd日'
;
// 日期中不包含年份,且month与day是中文
static
readonly
PATTERN_DATE_SLASH_WITHOUT_YEAR2
:
string
=
'MM-dd'
;
// 日期中不包含年份
// 仅时间格式(不包含日期)
static
readonly
PATTERN_TIME_DEFAULT
:
string
=
'HHmmss'
;
// 时分秒
...
...
@@ -331,6 +332,33 @@ export class DateTimeUtils {
public
static
getCurrentTimeMillis
()
:
number
{
return
new
Date
().
getTime
();
}
/**
* 获取文章发布时间
* */
public
static
getCommentTime
(
publishTime
:
number
)
:
string
{
let
currentTime
:
number
=
new
Date
().
getTime
();
let
timeGap
=
currentTime
-
publishTime
;
let
timeStr
=
""
if
(
timeGap
>=
60
*
60
*
1000
*
48
)
{
let
publishYear
=
new
Date
(
publishTime
).
getFullYear
();
let
currentYear
=
new
Date
(
currentTime
).
getFullYear
();
if
(
publishYear
==
currentYear
)
{
timeStr
=
this
.
formatDate
(
publishTime
,
DateTimeUtils
.
PATTERN_DATE_SLASH_WITHOUT_YEAR2
)
}
else
{
timeStr
=
this
.
formatDate
(
publishTime
)
}
}
else
if
(
timeGap
>
60
*
60
*
1000
*
24
)
{
timeStr
=
Math
.
floor
(
timeGap
/
(
60
*
60
*
1000
*
24
))
+
"天前"
;
}
else
if
(
timeGap
>
60
*
60
*
1000
)
{
// 1小时-24小时
timeStr
=
Math
.
floor
(
timeGap
/
(
60
*
60
*
1000
))
+
"小时前"
;
}
else
if
(
timeGap
>
60
*
1000
)
{
// 1分钟-59分钟
timeStr
=
Math
.
floor
(
timeGap
/
(
60
*
1000
))
+
"分钟前"
;
}
else
{
// 1秒钟-59秒钟
timeStr
=
"刚刚"
;
}
return
timeStr
;
}
}
// const dateTimeUtils = new DateTimeUtils()
\ No newline at end of file
...
...
Please
register
or
login
to post a comment