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
    127
    Thanks given
    36
    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  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    645
    Thanks given
    244
    Thanks received
    117
    Rep Power
    260
    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 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Registered Member
    Join Date
    May 2015
    Posts
    127
    Thanks given
    36
    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  
    Registered Member
    arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,595
    Thanks given
    161
    Thanks received
    256
    Rep Power
    407
    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 Thanker
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,828
    Thanks given
    6,828
    Thanks received
    164
    Rep Power
    2324
    [Only registered and activated users can see links. ]
    Thanks, MrClassic.

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. Thankful user:


  11. #6  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    645
    Thanks given
    244
    Thanks received
    117
    Rep Power
    260
    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 - [Only registered and activated users can see links. ]!
    KT - Drop tables: Simple and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers: Safe, Easy and Powerful - [Only registered and activated users can see links. ]
    KT - NbUtil: Make your kotlin easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    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)

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 Tutorials
    Replies: 9
    Last Post: 01-06-2008, 10:20 PM
  4. How to get the numbers you need for item coloring
    By Codyd536 in forum Tutorials
    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
  •