简体   繁体   中英

How do I get the number of the current week?

I want to write a simple app, which opens a website in a folder named with the current week number. So for example:

http://www.website.de/content/35/index.html

thats the basic structure. Thanks for your help.

Import java.util.Calendar and implement:

public static int getWeek() {
    return Calendar.getInstance().get(Calendar.WEEK_OF_YEAR);
}

Use calender for that like this -

Calendar calender = Calendar.getInstance();
Log.d("Current Week:" + calender.get(Calendar.WEEK_OF_YEAR));

for more details java.util.Calender

This is how you get the current week number:

    Calendar calendar = Calendar.getInstance();
    int week = calendar.get(Calendar.WEEK_OF_YEAR)

This is how you open a website:

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("http://www.website.de/content/"+week+"/index.html"));
            startActivity(intent);

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