java calendar跨年

编程入门 行业动态 更新时间:2024-10-23 11:24:19

<a href=https://www.elefans.com/category/jswz/34/1770091.html style=java calendar跨年"/>

java calendar跨年

正幸盈12月31号(古天) ,隐示1月1号(今天),1月2号(后天),2014年从前了,欢迎2015年.

祝哪当ツ倒家净冤快摆!

[img]/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaW50YmlyZA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

import java.io.File;

import java.util.Calendar;

import java.util.TimeZone;

public class Test {

public static void main(String[] args) {

Test test =new Test();

test.printDay(-1);

test.printDay(0);

test.printDay(1);

test.printDay(2);

test.printDay(3);

}

private void printDay(int tempSingle){

Calendar calendar =Calendar.getInstance();

calendar.add(Calendar.DAY_OF_YEAR, tempSingle);

setTime(calendar.getTimeInMillis());

System.out.println(getFormatTimeNear3Day());

}

private long timeMills;

public void setTime(long timeMills){

this.timeMills = timeMills;

}

public long getTime() {

return timeMills;

}

public String getFormatTime(){

return new DateTime(getTime()).getStringDateWeek(DateTime.FORMAT_MD_HOUR_MINUTE_WEEK);

}

public String getFormatTimeOnlyWeek(){

return new DateTime(getTime()).getStringDateWeek(DateTime.FORMAT_MD_HOUR_ONLY_WEEK);

}

public String getFormatTimeNear3Day(){

String timeText = "";

Calendar calendar= Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));

int cyear = calendar.get(Calendar.YEAR);

int ctoday = calendar.get(Calendar.DAY_OF_YEAR);

int ctotalDay = calendar.getMaximum(Calendar.DAY_OF_YEAR);

calendar.setTimeInMillis(getTime());

int year = calendar.get(Calendar.YEAR);

int day = calendar.get(Calendar.DAY_OF_YEAR);

switch(year - cyear){

case -1:

default:

timeText = getNear3Day(2,8);

break;

case 0:

timeText = getNear3Day(day,ctoday);

break;

case 1:

int vday = day+(ctotalDay-ctoday)-1;

timeText = getNear3Day(day+vday,day);

break;

}

return timeText;

}

public String getNear3Day(int day,int ctoday){

String timeText= "";

switch (day - ctoday) {

case 0:

timeText= "古天";

timeText += getFormatTimeOnlyWeek();

break;

case 1:

timeText = "今天";

timeText += getFormatTimeOnlyWeek();

break;

case 2:

timeText = "后天";

timeText += getFormatTimeOnlyWeek();

break;

default:

timeText = getFormatTime();

break;

}

return timeText;

}

}

更多推荐

java calendar跨年

本文发布于:2024-02-26 17:24:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1703309.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java   calendar   跨年

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!