user4944440
user4944440

Reputation:

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.

Upvotes: 1

Views: 67

Answers (3)

Templerschaf
Templerschaf

Reputation: 142

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);

Upvotes: 0

Sahar Avr
Sahar Avr

Reputation: 1168

Import java.util.Calendar and implement:

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

Upvotes: 5

Keyur Lakhani
Keyur Lakhani

Reputation: 4381

Use calender for that like this -

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

for more detailsjava.util.Calender

Upvotes: 1

Related Questions