gpt4 book ai didi

java - 如何在 Timepicker 中选择上午或下午时间?

转载 作者:行者123 更新时间:2023-12-01 21:15:48 25 4
gpt4 key购买 nike

我得到了不包括周末的两个日期之间的差异。但是我想在一天结束时获得上午的时间。因为如果员工在下午开始工作,那么我想添加许可日半时间。如何才能我做吗?

private void Calculation() {
final SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
Date d3 = null;
Date d4 = null;

try {
d3 = sdf.parse(izinSaatim); //String izinSaatim value parse to date
} catch (ParseException e) {
e.printStackTrace();
}
try {
d4 = sdf.parse(basSaatim);String basSaatim value parse to date
} catch (ParseException e) {
e.printStackTrace();
}
Calendar c3 = Calendar.getInstance();
c3.setTime(d3);
Calendar c4 = Calendar.getInstance();
c3.setTime(d4);
if(d3.getTime()>=Calendar.AM || d4.getTime()>=Calendar.AM){
//....
}
}

Difference between two date:

  private void hesapla() {

final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(izinTarihim);
} catch (ParseException e) {
e.printStackTrace();
}
try {
d2 = format.parse(basTarihim);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar c1 = Calendar.getInstance();
c1.setTime(d1);
int w1 = c1.get(Calendar.DAY_OF_WEEK);
c1.add(Calendar.DAY_OF_WEEK, -w1);

Calendar c2 = Calendar.getInstance();
c2.setTime(d2);
int w2 = c2.get(Calendar.DAY_OF_WEEK);
c2.add(Calendar.DAY_OF_WEEK, -w2);

long days = (c2.getTimeInMillis() - c1.getTimeInMillis()) / (1000 * 60 * 60 * 24);
long daysWithoutWeekendDays = days - (days * 2 / 7);
if (w1 == Calendar.SUNDAY && w2 != Calendar.SATURDAY) {
w1 = Calendar.MONDAY;
} else if (w1 == Calendar.SATURDAY && w2 != Calendar.SUNDAY) {
w1 = Calendar.FRIDAY;
}

if (w2 == Calendar.SUNDAY) {
w2 = Calendar.MONDAY;
} else if (w2 == Calendar.SATURDAY) {
w2 = Calendar.FRIDAY;
}
long a = daysWithoutWeekendDays - w1 + w2;

gunSayi = Long.toString(a);

kullanilan.setText(gunSayi);
}

最佳答案

用这个

 SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy hh.mm.ss.S aa");
String formattedDate = dateFormat.format(new Date()).toString();
System.out.println(formattedDate);

您将收到2005 年 8 月 11 日下午 12.25.15.375

关于java - 如何在 Timepicker 中选择上午或下午时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40176300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com