Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds-android
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
云深项目组
beyond-clouds-android
Commits
3cc48092
Commit
3cc48092
authored
Mar 19, 2020
by
张晋雄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
时间类
parent
415875e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
app/src/main/java/cn/yunliyunwai/beyondclouds/util/TimeUtils.java
+50
-0
No files found.
app/src/main/java/cn/yunliyunwai/beyondclouds/util/TimeUtils.java
0 → 100644
View file @
3cc48092
package
cn
.
yunliyunwai
.
beyondclouds
.
util
;
import
android.util.Log
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
public
class
TimeUtils
{
public
String
toMoment
(
Date
date
){
Calendar
now
=
Calendar
.
getInstance
();
now
.
setTime
(
new
Date
());
Calendar
to
=
Calendar
.
getInstance
();
to
.
setTime
(
date
);
int
year
=
now
.
get
(
Calendar
.
YEAR
)
-
to
.
get
(
Calendar
.
YEAR
);;
int
month
=
now
.
get
(
Calendar
.
MONTH
)
-
to
.
get
(
Calendar
.
MONTH
);;
int
day
=
now
.
get
(
Calendar
.
DAY_OF_MONTH
)
-
to
.
get
(
Calendar
.
DAY_OF_MONTH
);
int
hour
=
now
.
get
(
Calendar
.
HOUR
)
-
to
.
get
(
Calendar
.
HOUR
);
int
minute
=
now
.
get
(
Calendar
.
MINUTE
)
-
to
.
get
(
Calendar
.
MINUTE
);
int
second
=
now
.
get
(
Calendar
.
SECOND
)
-
to
.
get
(
Calendar
.
SECOND
);
if
(
year
>
0
){
return
year
+
"年前"
;
}
else
if
(
year
<
0
){
return
Math
.
abs
(
year
)+
"年后"
;
}
else
if
(
month
>
0
){
return
month
+
"个月前"
;
}
else
if
(
month
<
0
){
return
Math
.
abs
(
month
)+
"个月后"
;
}
else
if
(
day
>
0
){
return
day
+
"天前"
;
}
else
if
(
day
<
0
){
return
Math
.
abs
(
day
)+
"天后"
;
}
else
if
(
hour
>
0
){
return
hour
+
"小时前"
;
}
else
if
(
hour
<
0
){
return
Math
.
abs
(
hour
)+
"小时后"
;
}
else
if
(
minute
>
0
){
return
minute
+
"分钟前"
;
}
else
if
(
minute
!=
0
){
return
Math
.
abs
(
minute
)+
"分钟后"
;
}
else
if
(
second
>
0
){
return
second
+
"秒前"
;
}
else
{
return
Math
.
abs
(
second
)+
"秒后"
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment