Thread: How to get the date (Shorten)

Results 1 to 6 of 6
  1. #1 How to get the date (Shorten) 
    Registered Member
    Join Date
    May 2015
    Posts
    158
    Thanks given
    52
    Thanks received
    5
    Rep Power
    11
    Code:
    public String getMemberTill() {
    return "<col=" + color + ">" + (new Date(memberTill));
    }
    The code I'm using to show membership expiration date is written out like so.
    Sun May 18 20:36:30 MTS 2019"
    This is so unnecessary to show all that, I just want the month and day "May 19", or "Sun May 19" if possible.

    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;
    	}
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    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())));
        }
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Registered Member
    Join Date
    May 2015
    Posts
    158
    Thanks given
    52
    Thanks received
    5
    Rep Power
    11
    Quote Originally Posted by nbness2 View Post
    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()));
    	}
    Reply With Quote  
     

  6. Thankful user:


  7. #4  
    Community Veteran


    Arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,950
    Thanks given
    210
    Thanks received
    349
    Rep Power
    1376
    Start of with adding either a long value or date value that the player save / load.
    Then use that to display your time.


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  8. Thankful user:


  9. #5  
    Registered MrClassic
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    15
    Posts
    2,063
    Thanks given
    24,154
    Thanks received
    551
    Rep Power
    5000
    Reply With Quote  
     

  10. Thankful user:


  11. #6  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Quote Originally Posted by Levels View Post
    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()));
    }
    If you can get the date of the ending membership, you can use SimpleDateFormat 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);
    }
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  12. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. how to get the dodian client on your website
    By Dawgg in forum Tutorials
    Replies: 16
    Last Post: 06-11-2008, 08:53 PM
  2. How to get the full version of hypercam2 free!
    By Owner of Hunterscape in forum Chat
    Replies: 0
    Last Post: 05-05-2008, 03:01 PM
  3. how to get the exact runescape page.
    By Dawgg in forum Website Development
    Replies: 9
    Last Post: 01-06-2008, 10:20 PM
  4. Replies: 24
    Last Post: 09-15-2007, 04:32 PM
  5. Replies: 16
    Last Post: 09-06-2007, 05:12 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •