Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**
     * Get the displayable date from week and year
     * @param week week of year
     * @param year year
     * @return Date string for displaying
     */
    public static String getDate(int week, int year) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
        Calendar cal = Calendar.getInstance();
        //        Log.i(TAG, sdf.format(cal.getTime()));
        cal.set(Calendar.YEAR, year);
        //        Log.i(TAG, sdf.format(cal.getTime()));
        cal.set(Calendar.WEEK_OF_YEAR, week);
        //        Log.i(TAG, sdf.format(cal.getTime()));
        cal.set(Calendar.DAY_OF_WEEK, 1);
        //        Log.i(TAG, sdf.format(cal.getTime()));
        String start = sdf.format(cal.getTime());
        cal.set(Calendar.DAY_OF_WEEK, 7);
        //        Log.i(TAG, sdf.format(cal.getTime()));
        String end = sdf.format(cal.getTime());
        return start + " to " + end;
    }
}