bug fix:1.发起跨房PK自定义时间输入方式优化 2.钻石开箱是否显示处理时间相等的情况 3.去掉重PK方进入房间提示功能 4.PK面板有时候展开失败的问题
This commit is contained in:
@@ -8,6 +8,7 @@ import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.PopupWindow
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
@@ -54,14 +55,14 @@ class RoomPKBoardView @JvmOverloads constructor(
|
||||
if (CommonUtils.isFastDoubleClick(1000)) return@setOnClickListener
|
||||
binding.groupRank.isVisible = !binding.groupRank.isVisible
|
||||
if (binding.groupRank.isVisible) {
|
||||
binding.root.setBackgroundResource(R.drawable.bg_room_pk_board)
|
||||
binding.root.updateLayoutParams<LayoutParams> {
|
||||
binding.clRoot.setBackgroundResource(R.drawable.bg_room_pk_board)
|
||||
binding.clRoot.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||
width = ScreenUtil.dip2px(339f)
|
||||
height = ScreenUtil.dip2px(233f)
|
||||
}
|
||||
} else {
|
||||
binding.root.setBackgroundResource(R.drawable.bg_room_pk_board_small)
|
||||
binding.root.updateLayoutParams<LayoutParams> {
|
||||
binding.clRoot.setBackgroundResource(R.drawable.bg_room_pk_board_small)
|
||||
binding.clRoot.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||
width = ScreenUtil.dip2px(339f)
|
||||
height = ScreenUtil.dip2px(137f)
|
||||
}
|
||||
@@ -84,7 +85,7 @@ class RoomPKBoardView @JvmOverloads constructor(
|
||||
|
||||
binding.tvGoAnotherRoom.setOnClickListener {
|
||||
roomPkBean?.let {
|
||||
AVRoomActivity.startForFromType(context, it.aUid, AVRoomActivity.FROM_TYPE_ROOM_PK)
|
||||
AVRoomActivity.start(context, it.aUid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +138,8 @@ class RoomPKBoardView @JvmOverloads constructor(
|
||||
binding.tvTime.text = roomPkBean?.endTime?.let {
|
||||
val remainTime = (it - CurrentTimeUtils.getCurrentTime()).toInt() / 1000
|
||||
binding.tvTime.setTextColor(Color.parseColor(if (remainTime <= 30) "#ff87a1" else "#fff600"))
|
||||
binding.tvTime.isVisible = remainTime > 0
|
||||
binding.tvEndHint.isVisible = remainTime <= 0
|
||||
TimeUtil.secToTime(remainTime)
|
||||
} ?: "00:00"
|
||||
}
|
||||
|
@@ -58,21 +58,21 @@ class RoomPKCreateActivity : BaseViewBindingActivity<ActivityRoomPkCreateBinding
|
||||
}
|
||||
|
||||
binding.rbMin10.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked){
|
||||
if (isChecked) {
|
||||
pkTime = 10
|
||||
binding.editTime.setText("")
|
||||
checkCommitEnable()
|
||||
}
|
||||
}
|
||||
binding.rbMin20.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked){
|
||||
if (isChecked) {
|
||||
pkTime = 20
|
||||
binding.editTime.setText("")
|
||||
checkCommitEnable()
|
||||
}
|
||||
}
|
||||
binding.rbMin30.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked){
|
||||
if (isChecked) {
|
||||
pkTime = 30
|
||||
binding.editTime.setText("")
|
||||
checkCommitEnable()
|
||||
@@ -84,12 +84,6 @@ class RoomPKCreateActivity : BaseViewBindingActivity<ActivityRoomPkCreateBinding
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
s?.toString().ifNotNullOrEmpty {
|
||||
pkTime = it.toIntOrDef(0)
|
||||
if (pkTime > 180) {
|
||||
binding.editTime.setText("180")
|
||||
}
|
||||
if (pkTime < 5) {
|
||||
binding.editTime.setText("5")
|
||||
}
|
||||
if (pkTime != 0) {
|
||||
binding.rg.clearCheck()
|
||||
}
|
||||
@@ -99,7 +93,10 @@ class RoomPKCreateActivity : BaseViewBindingActivity<ActivityRoomPkCreateBinding
|
||||
})
|
||||
|
||||
binding.tvOk.setOnClickListener {
|
||||
if (!checkCommitEnable()) return@setOnClickListener
|
||||
if (pkTime < 5 || pkTime > 180) {
|
||||
"PK时长在5-180分钟内,请重新输入!".toast()
|
||||
return@setOnClickListener
|
||||
}
|
||||
currSimpleRoomInfo?.let {
|
||||
RoomPKModel.initiateRoomPK(
|
||||
it.roomUid,
|
||||
@@ -114,7 +111,7 @@ class RoomPKCreateActivity : BaseViewBindingActivity<ActivityRoomPkCreateBinding
|
||||
"发起邀请成功!".toast()
|
||||
finish()
|
||||
}, { throwable ->
|
||||
dialogManager.showTipsDialog(throwable.message,null)
|
||||
dialogManager.showTipsDialog(throwable.message, null)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@@ -2557,9 +2557,6 @@ public class MessageView extends FrameLayout {
|
||||
enterText = " 的邀请,进入了房间";
|
||||
}
|
||||
|
||||
if (fromType == AVRoomActivity.FROM_TYPE_ROOM_PK) {
|
||||
enterText = " 从PK方进入了房间";
|
||||
}
|
||||
text.append(enterText, new ForegroundColorSpan(whiteColor));
|
||||
|
||||
//如果自己在麦上,增加一个欢迎ta的按钮,并且这条消息不是自己的
|
||||
|
@@ -186,6 +186,7 @@
|
||||
android:background="@drawable/bg_room_pk_common_btn"
|
||||
android:hint="自定义(5-180)"
|
||||
android:inputType="number"
|
||||
android:maxLength="3"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="50dp"
|
||||
android:textColor="@color/text_title_white"
|
||||
@@ -223,9 +224,9 @@
|
||||
android:layout_marginEnd="12dp"
|
||||
android:background="@drawable/bg_room_pk_common_btn"
|
||||
android:hint="选填,10个字以内"
|
||||
android:maxLength="10"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="50dp"
|
||||
android:maxLength="10"
|
||||
android:textColor="@color/text_title_white"
|
||||
android:textColorHint="@color/white_transparent_50"
|
||||
android:textSize="15sp"
|
||||
|
@@ -1,8 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="339dp"
|
||||
android:layout_height="233dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/cl_root"
|
||||
android:layout_width="339dp"
|
||||
android:layout_height="233dp"
|
||||
android:background="@drawable/bg_room_pk_board"
|
||||
android:orientation="horizontal"
|
||||
@@ -22,6 +27,21 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_end_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:includeFontPadding="false"
|
||||
android:text="PK结果计算中..."
|
||||
android:textColor="#fffff600"
|
||||
android:textSize="11dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.72"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<View
|
||||
android:id="@+id/view_help_anchor"
|
||||
android:layout_width="1dp"
|
||||
@@ -136,8 +156,9 @@
|
||||
android:id="@+id/svga_hot"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="27dp"
|
||||
android:layout_marginBottom="18dp"
|
||||
app:autoPlay="true"
|
||||
app:layout_constraintBottom_toBottomOf="@id/pb_score"
|
||||
app:layout_constraintBottom_toBottomOf="@id/iv_details"
|
||||
app:layout_constraintEnd_toStartOf="@id/iv_avatar_right"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_avatar_left"
|
||||
@@ -257,4 +278,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="view_rank_list_charm_right,view_rank_list_contribute_right,view_rank_list_charm_left,view_rank_list_contribute_left,tv_charm_title,tv_contribute_title" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
@@ -14,7 +14,6 @@
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:lineSpacingExtra="3dp"
|
||||
android:text="@string/room_pk_help"
|
||||
android:textColor="@color/text_title_white"
|
||||
android:textSize="12sp" />
|
||||
|
@@ -48,6 +48,7 @@ public class TimeUtils {
|
||||
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final long MILLIS_OF_SEC = 1000;
|
||||
|
||||
public static String getCurrentDateStr() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.getDefault());
|
||||
@@ -157,8 +158,6 @@ public class TimeUtils {
|
||||
return c.getTimeInMillis();
|
||||
}
|
||||
|
||||
public static final long MILLIS_OF_SEC = 1000;
|
||||
|
||||
/**
|
||||
* Get current time in secs.
|
||||
*
|
||||
@@ -427,6 +426,308 @@ public class TimeUtils {
|
||||
return t * scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将毫秒转换为年月日时分秒 ,只拿时分秒
|
||||
*
|
||||
* @author GaoHuanjie
|
||||
*/
|
||||
public static String getYearMonthDayHourMinuteSecond(long timeMillis) {
|
||||
int timezone = 8; // 时区
|
||||
long totalSeconds = timeMillis / 1000;
|
||||
totalSeconds += 60 * 60 * timezone;
|
||||
int second = (int) (totalSeconds % 60);// 秒
|
||||
long totalMinutes = totalSeconds / 60;
|
||||
int minute = (int) (totalMinutes % 60);// 分
|
||||
long totalHours = totalMinutes / 60;
|
||||
int hour = (int) (totalHours % 24);// 时
|
||||
int totalDays = (int) (totalHours / 24);
|
||||
int _year = 1970;
|
||||
int year = _year + totalDays / 366;
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
int diffDays;
|
||||
boolean leapYear;
|
||||
while (true) {
|
||||
int diff = (year - _year) * 365;
|
||||
diff += (year - 1) / 4 - (_year - 1) / 4;
|
||||
diff -= ((year - 1) / 100 - (_year - 1) / 100);
|
||||
diff += (year - 1) / 400 - (_year - 1) / 400;
|
||||
diffDays = totalDays - diff;
|
||||
leapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
|
||||
if (!leapYear && diffDays < 365 || leapYear && diffDays < 366) {
|
||||
break;
|
||||
} else {
|
||||
year++;
|
||||
}
|
||||
}
|
||||
|
||||
int[] monthDays;
|
||||
if (diffDays >= 59 && leapYear) {
|
||||
monthDays = new int[]{-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
|
||||
} else {
|
||||
monthDays = new int[]{-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
|
||||
}
|
||||
for (int i = monthDays.length - 1; i >= 1; i--) {
|
||||
if (diffDays >= monthDays[i]) {
|
||||
month = i;
|
||||
day = diffDays - monthDays[i] + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String hours;
|
||||
String minutes;
|
||||
String seconds;
|
||||
if (hour < 10) {
|
||||
hours = "0" + hour;
|
||||
} else {
|
||||
hours = "" + hour;
|
||||
}
|
||||
if (minute < 10) {
|
||||
minutes = "0" + minute;
|
||||
} else {
|
||||
minutes = "" + minute;
|
||||
}
|
||||
if (second < 10) {
|
||||
seconds = "0" + second;
|
||||
} else {
|
||||
seconds = "" + second;
|
||||
}
|
||||
|
||||
// return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
}
|
||||
|
||||
public static Date getTimesnight(int i) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, i);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/*获得指定天数的0点和24点*/
|
||||
public static Date getTimesnights(Date time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(time);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间戳ms 转成星座
|
||||
* 白羊:0321~0420 天秤:0924~1023
|
||||
* 金牛:0421~0521 天蝎:1024~1122
|
||||
* 双子:0522~0621 射手:1123~1221
|
||||
* 巨蟹:0622~0722 摩羯:1222~0120
|
||||
* 狮子:0723~0823 水瓶:0121~0219
|
||||
* 处女:0824~0923 双鱼:0220~0320
|
||||
*/
|
||||
public static String msToConstellation(long ms) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(ms);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
Log.e("mouse_debug", month + ", " + day);
|
||||
String xingzuo = "";
|
||||
switch (month) {
|
||||
case 1:
|
||||
xingzuo = day < 21 ? "摩羯座" : "水瓶座";
|
||||
break;
|
||||
case 2:
|
||||
xingzuo = day < 20 ? "水瓶座" : "双鱼座";
|
||||
break;
|
||||
case 3:
|
||||
xingzuo = day < 21 ? "双鱼座" : "白羊座";
|
||||
break;
|
||||
case 4:
|
||||
xingzuo = day < 21 ? "白羊座" : "金牛座";
|
||||
break;
|
||||
case 5:
|
||||
xingzuo = day < 22 ? "金牛座" : "双子座";
|
||||
break;
|
||||
case 6:
|
||||
xingzuo = day < 22 ? "双子座" : "巨蟹座";
|
||||
break;
|
||||
case 7:
|
||||
xingzuo = day < 23 ? "巨蟹座" : "狮子座";
|
||||
break;
|
||||
case 8:
|
||||
xingzuo = day < 24 ? "狮子座" : "处女座";
|
||||
break;
|
||||
case 9:
|
||||
xingzuo = day < 24 ? "处女座" : "天秤座";
|
||||
break;
|
||||
case 10:
|
||||
xingzuo = day < 24 ? "天秤座" : "天蝎座";
|
||||
break;
|
||||
case 11:
|
||||
xingzuo = day < 23 ? "天蝎座" : "射手座";
|
||||
break;
|
||||
case 12:
|
||||
xingzuo = day < 22 ? "射手座" : "摩羯座";
|
||||
break;
|
||||
}
|
||||
return xingzuo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是 第二天
|
||||
*
|
||||
* @param cacheTime 和 当前时间对比,判断现在是不是第二天了
|
||||
* @return
|
||||
*/
|
||||
public static boolean isTomorrow(long cacheTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int currYear = calendar.get(Calendar.YEAR);
|
||||
int currMonth = calendar.get(Calendar.MONTH);
|
||||
int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
calendar.setTimeInMillis(cacheTime);
|
||||
int cacheYear = calendar.get(Calendar.YEAR);
|
||||
int cacheMonth = calendar.get(Calendar.MONTH);
|
||||
int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
if (currYear > cacheYear) {
|
||||
return true;
|
||||
}
|
||||
boolean equalYear = currYear == cacheYear;
|
||||
if (equalYear && currMonth > cacheMonth) {
|
||||
return true;
|
||||
}
|
||||
return equalYear && currMonth == cacheMonth && currDayOfMonth > cacheDayOfMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cacheTime 和 当前时间对比,判断现在是不是当天
|
||||
* @return -
|
||||
*/
|
||||
public static boolean isToday(long cacheTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int currYear = calendar.get(Calendar.YEAR);
|
||||
int currMonth = calendar.get(Calendar.MONTH);
|
||||
int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
calendar.setTimeInMillis(cacheTime);
|
||||
int cacheYear = calendar.get(Calendar.YEAR);
|
||||
int cacheMonth = calendar.get(Calendar.MONTH);
|
||||
int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
return currYear == cacheYear && currMonth == cacheMonth && currDayOfMonth == cacheDayOfMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cacheTime 和 当前时间对比,是不是同一年
|
||||
* @return -
|
||||
*/
|
||||
public static boolean isSameYear(long cacheTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int currYear = calendar.get(Calendar.YEAR);
|
||||
calendar.setTimeInMillis(cacheTime);
|
||||
int cacheYear = calendar.get(Calendar.YEAR);
|
||||
return currYear == cacheYear;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得系统时间 年、月、日、小时、分钟
|
||||
*
|
||||
* @return HashMap
|
||||
*/
|
||||
public static int getTime24() {
|
||||
SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA);
|
||||
SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA);
|
||||
hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间
|
||||
mm.setTimeZone(TimeZone.getTimeZone("GMT+08"));
|
||||
Date date = new Date();
|
||||
String hour = hh.format(date);
|
||||
String minute = mm.format(date);
|
||||
return Integer.parseInt(hour + minute);
|
||||
}
|
||||
|
||||
public static boolean getTimeLimit(int start_hour, int end_hour) {
|
||||
if (start_hour == end_hour) return false;
|
||||
SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA);
|
||||
SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA);
|
||||
hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间
|
||||
mm.setTimeZone(TimeZone.getTimeZone("GMT+08"));
|
||||
Date date = new Date();
|
||||
String hour = hh.format(date);
|
||||
String minute = mm.format(date);
|
||||
Log.i("stf", "--hour:minute-->" + hour + ":" + minute);
|
||||
int currentTime = Integer.parseInt(hour + minute);
|
||||
LogUtil.print("start" + start_hour);
|
||||
LogUtil.print("end" + end_hour);
|
||||
LogUtil.print("minuteOfDay" + currentTime);
|
||||
if (currentTime >= start_hour && currentTime <= end_hour) {
|
||||
LogUtil.print("工作时间内" + hour + ":" + minute);
|
||||
return true;
|
||||
} else {
|
||||
if (start_hour > end_hour) {
|
||||
if (currentTime >= start_hour || currentTime <= end_hour) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LogUtil.print("工作时间外" + hour + ":" + minute);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年月的第一天
|
||||
*
|
||||
* @param ym yyyy-MM
|
||||
* @return
|
||||
*/
|
||||
public static String getFirstDayOfMonth(String ym) {
|
||||
String arr[] = ym.split("-");
|
||||
|
||||
int year = Integer.parseInt(arr[0]);
|
||||
int month = Integer.parseInt(arr[1]);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
//设置年份
|
||||
cal.set(Calendar.YEAR, year);
|
||||
|
||||
//设置月份
|
||||
cal.set(Calendar.MONTH, month - 1);
|
||||
//获取某月最小天数
|
||||
int firstDay = cal.getMinimum(Calendar.DATE);
|
||||
//设置日历中月份的最小天数
|
||||
cal.set(Calendar.DAY_OF_MONTH, firstDay);
|
||||
//格式化日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
return sdf.format(cal.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年月的最后一天
|
||||
*
|
||||
* @param ym
|
||||
* @return
|
||||
*/
|
||||
public static String getLastDayOfMonth(String ym) {
|
||||
String arr[] = ym.split("-");
|
||||
|
||||
int year = Integer.parseInt(arr[0]);
|
||||
int month = Integer.parseInt(arr[1]);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
//设置年份
|
||||
cal.set(Calendar.YEAR, year);
|
||||
//设置月份
|
||||
cal.set(Calendar.MONTH, month - 1);
|
||||
//获取某月最大天数
|
||||
int lastDay = cal.getActualMaximum(Calendar.DATE);
|
||||
//设置日历中月份的最大天数
|
||||
cal.set(Calendar.DAY_OF_MONTH, lastDay);
|
||||
//格式化日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return sdf.format(cal.getTime());
|
||||
}
|
||||
|
||||
public static class YEARS {
|
||||
public static long toMillis(long years) {
|
||||
return checkOverflow(years, DAYS_OF_YEAR * HOURS_OF_DAY * MINUTES_OF_HOUR * SECONDS_OF_MINUTE * MILLIS_OF_SECOND);
|
||||
@@ -609,311 +910,6 @@ public class TimeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将毫秒转换为年月日时分秒 ,只拿时分秒
|
||||
*
|
||||
* @author GaoHuanjie
|
||||
*/
|
||||
public static String getYearMonthDayHourMinuteSecond(long timeMillis) {
|
||||
int timezone = 8; // 时区
|
||||
long totalSeconds = timeMillis / 1000;
|
||||
totalSeconds += 60 * 60 * timezone;
|
||||
int second = (int) (totalSeconds % 60);// 秒
|
||||
long totalMinutes = totalSeconds / 60;
|
||||
int minute = (int) (totalMinutes % 60);// 分
|
||||
long totalHours = totalMinutes / 60;
|
||||
int hour = (int) (totalHours % 24);// 时
|
||||
int totalDays = (int) (totalHours / 24);
|
||||
int _year = 1970;
|
||||
int year = _year + totalDays / 366;
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
int diffDays;
|
||||
boolean leapYear;
|
||||
while (true) {
|
||||
int diff = (year - _year) * 365;
|
||||
diff += (year - 1) / 4 - (_year - 1) / 4;
|
||||
diff -= ((year - 1) / 100 - (_year - 1) / 100);
|
||||
diff += (year - 1) / 400 - (_year - 1) / 400;
|
||||
diffDays = totalDays - diff;
|
||||
leapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
|
||||
if (!leapYear && diffDays < 365 || leapYear && diffDays < 366) {
|
||||
break;
|
||||
} else {
|
||||
year++;
|
||||
}
|
||||
}
|
||||
|
||||
int[] monthDays;
|
||||
if (diffDays >= 59 && leapYear) {
|
||||
monthDays = new int[]{-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
|
||||
} else {
|
||||
monthDays = new int[]{-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
|
||||
}
|
||||
for (int i = monthDays.length - 1; i >= 1; i--) {
|
||||
if (diffDays >= monthDays[i]) {
|
||||
month = i;
|
||||
day = diffDays - monthDays[i] + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String hours;
|
||||
String minutes;
|
||||
String seconds;
|
||||
if (hour < 10) {
|
||||
hours = "0" + hour;
|
||||
} else {
|
||||
hours = "" + hour;
|
||||
}
|
||||
if (minute < 10) {
|
||||
minutes = "0" + minute;
|
||||
} else {
|
||||
minutes = "" + minute;
|
||||
}
|
||||
if (second < 10) {
|
||||
seconds = "0" + second;
|
||||
} else {
|
||||
seconds = "" + second;
|
||||
}
|
||||
|
||||
// return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
}
|
||||
|
||||
public static Date getTimesnight(int i) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, i);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/*获得指定天数的0点和24点*/
|
||||
public static Date getTimesnights(Date time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(time);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间戳ms 转成星座
|
||||
* 白羊:0321~0420 天秤:0924~1023
|
||||
* 金牛:0421~0521 天蝎:1024~1122
|
||||
* 双子:0522~0621 射手:1123~1221
|
||||
* 巨蟹:0622~0722 摩羯:1222~0120
|
||||
* 狮子:0723~0823 水瓶:0121~0219
|
||||
* 处女:0824~0923 双鱼:0220~0320
|
||||
*/
|
||||
public static String msToConstellation(long ms) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(ms);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
Log.e("mouse_debug", month + ", " + day);
|
||||
String xingzuo = "";
|
||||
switch (month) {
|
||||
case 1:
|
||||
xingzuo = day < 21 ? "摩羯座" : "水瓶座";
|
||||
break;
|
||||
case 2:
|
||||
xingzuo = day < 20 ? "水瓶座" : "双鱼座";
|
||||
break;
|
||||
case 3:
|
||||
xingzuo = day < 21 ? "双鱼座" : "白羊座";
|
||||
break;
|
||||
case 4:
|
||||
xingzuo = day < 21 ? "白羊座" : "金牛座";
|
||||
break;
|
||||
case 5:
|
||||
xingzuo = day < 22 ? "金牛座" : "双子座";
|
||||
break;
|
||||
case 6:
|
||||
xingzuo = day < 22 ? "双子座" : "巨蟹座";
|
||||
break;
|
||||
case 7:
|
||||
xingzuo = day < 23 ? "巨蟹座" : "狮子座";
|
||||
break;
|
||||
case 8:
|
||||
xingzuo = day < 24 ? "狮子座" : "处女座";
|
||||
break;
|
||||
case 9:
|
||||
xingzuo = day < 24 ? "处女座" : "天秤座";
|
||||
break;
|
||||
case 10:
|
||||
xingzuo = day < 24 ? "天秤座" : "天蝎座";
|
||||
break;
|
||||
case 11:
|
||||
xingzuo = day < 23 ? "天蝎座" : "射手座";
|
||||
break;
|
||||
case 12:
|
||||
xingzuo = day < 22 ? "射手座" : "摩羯座";
|
||||
break;
|
||||
}
|
||||
return xingzuo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是 第二天
|
||||
*
|
||||
* @param cacheTime 和 当前时间对比,判断现在是不是第二天了
|
||||
* @return
|
||||
*/
|
||||
public static boolean isTomorrow(long cacheTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int currYear = calendar.get(Calendar.YEAR);
|
||||
int currMonth = calendar.get(Calendar.MONTH);
|
||||
int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
calendar.setTimeInMillis(cacheTime);
|
||||
int cacheYear = calendar.get(Calendar.YEAR);
|
||||
int cacheMonth = calendar.get(Calendar.MONTH);
|
||||
int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
if (currYear > cacheYear) {
|
||||
return true;
|
||||
}
|
||||
boolean equalYear = currYear == cacheYear;
|
||||
if (equalYear && currMonth > cacheMonth) {
|
||||
return true;
|
||||
}
|
||||
return equalYear && currMonth == cacheMonth && currDayOfMonth > cacheDayOfMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param cacheTime 和 当前时间对比,判断现在是不是当天
|
||||
* @return -
|
||||
*/
|
||||
public static boolean isToday(long cacheTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int currYear = calendar.get(Calendar.YEAR);
|
||||
int currMonth = calendar.get(Calendar.MONTH);
|
||||
int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
calendar.setTimeInMillis(cacheTime);
|
||||
int cacheYear = calendar.get(Calendar.YEAR);
|
||||
int cacheMonth = calendar.get(Calendar.MONTH);
|
||||
int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
return currYear == cacheYear && currMonth == cacheMonth && currDayOfMonth == cacheDayOfMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param cacheTime 和 当前时间对比,是不是同一年
|
||||
* @return -
|
||||
*/
|
||||
public static boolean isSameYear(long cacheTime) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int currYear = calendar.get(Calendar.YEAR);
|
||||
calendar.setTimeInMillis(cacheTime);
|
||||
int cacheYear = calendar.get(Calendar.YEAR);
|
||||
return currYear == cacheYear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获得系统时间 年、月、日、小时、分钟
|
||||
* @return HashMap
|
||||
*/
|
||||
public static int getTime24(){
|
||||
SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA);
|
||||
SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA);
|
||||
hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间
|
||||
mm.setTimeZone(TimeZone.getTimeZone("GMT+08"));
|
||||
Date date = new Date();
|
||||
String hour = hh.format(date);
|
||||
String minute = mm.format(date);
|
||||
return Integer.parseInt(hour +minute);
|
||||
}
|
||||
|
||||
public static boolean getTimeLimit(int start_hour,int end_hour) {
|
||||
SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA);
|
||||
SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA);
|
||||
hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间
|
||||
mm.setTimeZone(TimeZone.getTimeZone("GMT+08"));
|
||||
Date date = new Date();
|
||||
String hour = hh.format(date);
|
||||
String minute = mm.format(date);
|
||||
Log.i("stf", "--hour:minute-->" + hour + ":" + minute);
|
||||
int currentTime = Integer.parseInt(hour +minute);
|
||||
LogUtil.print("start" +start_hour);
|
||||
LogUtil.print("end" +end_hour);
|
||||
LogUtil.print("minuteOfDay" +currentTime);
|
||||
if (currentTime >= start_hour && currentTime <= end_hour) {
|
||||
LogUtil.print("工作时间内" + hour + ":" + minute);
|
||||
return true;
|
||||
} else {
|
||||
if (start_hour > end_hour){
|
||||
if (currentTime >= start_hour || currentTime <= end_hour){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LogUtil.print( "工作时间外" + hour + ":" + minute);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年月的第一天
|
||||
* @param ym yyyy-MM
|
||||
* @return
|
||||
*/
|
||||
public static String getFirstDayOfMonth(String ym) {
|
||||
String arr[] = ym.split("-");
|
||||
|
||||
int year = Integer.parseInt(arr[0]);
|
||||
int month = Integer.parseInt(arr[1]);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
//设置年份
|
||||
cal.set(Calendar.YEAR, year);
|
||||
|
||||
//设置月份
|
||||
cal.set(Calendar.MONTH, month - 1);
|
||||
//获取某月最小天数
|
||||
int firstDay = cal.getMinimum(Calendar.DATE);
|
||||
//设置日历中月份的最小天数
|
||||
cal.set(Calendar.DAY_OF_MONTH, firstDay);
|
||||
//格式化日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
return sdf.format(cal.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年月的最后一天
|
||||
* @param ym
|
||||
* @return
|
||||
*/
|
||||
public static String getLastDayOfMonth(String ym) {
|
||||
String arr[] = ym.split("-");
|
||||
|
||||
int year = Integer.parseInt(arr[0]);
|
||||
int month = Integer.parseInt(arr[1]);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
//设置年份
|
||||
cal.set(Calendar.YEAR, year);
|
||||
//设置月份
|
||||
cal.set(Calendar.MONTH, month - 1);
|
||||
//获取某月最大天数
|
||||
int lastDay = cal.getActualMaximum(Calendar.DATE);
|
||||
//设置日历中月份的最大天数
|
||||
cal.set(Calendar.DAY_OF_MONTH, lastDay);
|
||||
//格式化日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return sdf.format(cal.getTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public static boolean getTimeLimit() {
|
||||
// SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA);
|
||||
|
Reference in New Issue
Block a user