简体   繁体   中英

Get system's date ddmmyyyy

It's probably an easy question but how do you get the system date in format as ddmmyyyy in eclipse. So without any letters, spaces or other characters?

String todayAsString = new SimpleDateFormat("ddMMyyyy").format(new Date());

Eclipse is an IDE. Java is the language. Googling for "format a date in Java" and "current date in Java" would have led you to hundreds of pages telling you the answer. What matters is the language: Java. Not the IDE, which is just a tool to generate and compile Java code.

You can use this code, And can change the format to whatever you like.

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainClass {
    public static void main(String[] args) {
        String pattern = "MMddyyyy";
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        // formatting
        System.out.println(format.format(new Date()));
    }
}

Try this:

               Calendar cal= Calendar.getInstance();
               String cal_for_month = cal.get(Calendar.MONTH);
               String cal_for_year = cal.get(Calendar.YEAR);
                String cal_for_day = cal.get(Calendar.DAY_OF_MONTH);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM