|
The code I'm using to show membership expiration date is written out like so.Code:public String getMemberTill() { return "<col=" + color + ">" + (new Date(memberTill)); }
This is so unnecessary to show all that, I just want the month and day "May 19", or "Sun May 19" if possible.Sun May 18 20:36:30 MTS 2019"
EDIT:
I tried something like this, it doesn't give the correct month.
Code:public String getMemberTill() { Calendar memberTill = Calendar.getInstance(); int day = memberTill.get(Calendar.DAY_OF_MONTH); int month = memberTill.get(Calendar.MONTH); int year = memberTill.get(Calendar.YEAR); return "<col=" + color + ">" + month " - " + day; }
This works fine for me. For some reason month starts at 0, so you have to add 1.
Also string splitting is your friend if the strings are consistent!
Code:public static String shortDateString(Date date) { String dateString = date.toString(); return dateString.substring(0, dateString.indexOf(":") - 3); } public static void main(String[] args) { Calendar calendarInstance = Calendar.getInstance(); int currentYear = calendarInstance.get(Calendar.YEAR); int currentMonth = calendarInstance.get(Calendar.MONTH) + 1; int currentDayOfMonth = calendarInstance.get(Calendar.DAY_OF_MONTH); System.out.println("Current year is: "+currentYear); System.out.println("Current month is: "+currentMonth); System.out.println("Current day of month is: "+currentDayOfMonth); System.out.println("Current date is: "+shortDateString(new Date(calendarInstance.getTimeInMillis()))); }
This is great for getting the current date, but how would I get the date of the time the player's memberships ends?
Code:public String getMemberTill() { Calendar memberTill = Calendar.getInstance(); return "<col=" + color + ">" + shortDateString(new Date(memberTill.getTimeInMillis())); }
Start of with adding either a long value or date value that the player save / load.
Then use that to display your time.
If you can get the date of the ending membership, you can useSimpleDateFormat
to get the time in milliseconds of that day, and even down to the second if you want to.
d is day, M is month, y is year, h is hour, m is minute, s is second, you can leave out whatever you want to.
Code:static SimpleDateFormat dateFormat = new SimpleDateFormat("dd MM yyyy"); public static Date getDateFor(String dateString) throws java.text.ParseException { return dateFormat.parse(dateString); }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |