Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Calendar c = Calendar.getInstance();
- DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
- c.setTime( sdf.parse("31/12/2010"));
- out.println( c.get( Calendar.WEEK_OF_YEAR ) );
- public static void main(String[] args) throws ParseException {
- DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
- Date lastDec2010 = sdf.parse("31/12/2010");
- Calendar calUs = Calendar.getInstance(Locale.US);
- calUs.setTime(lastDec2010);
- Calendar calDe = Calendar.getInstance(Locale.GERMAN);
- calDe.setTime(lastDec2010);
- System.out.println( "us: " + calUs.get( Calendar.WEEK_OF_YEAR ) );
- System.out.println( "de: " + calDe.get( Calendar.WEEK_OF_YEAR ) );
- }
- us: 1
- de: 52
- Calendar c = Calendar.getInstance();
- c.setMinimalDaysInFirstWeek(7);//anything more than 1 will work in this year
- DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
- c.setTime( sdf.parse("31/12/2010"));
- System.out.println( c.get( Calendar.WEEK_OF_YEAR ) );
- 52
- java.time.LocalDate.parse(
- "31/12/2010" ,
- DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT ).withLocale( Locale.UK )
- )
- .get( IsoFields.WEEK_OF_WEEK_BASED_YEAR )
- org.threeten.extra.YearWeek.from( // Convert from a `LocalDate` object to a `YearWeek` object representing the entire week of that date’s week-based year.
- java.time.LocalDate.parse( "31/12/2010" , DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT ).withLocale( Locale.UK )
- ).getWeek() // Extract an integer number of that week of week-based-year, either 1-52 or 1-53 depending on the year.
- ZoneId zoneId = ZoneId.of ( "America/Montreal" );
- ZonedDateTime now = ZonedDateTime.now ( zoneId );
- int week = now.get ( IsoFields.WEEK_OF_WEEK_BASED_YEAR );
- int weekYear = now.get ( IsoFields.WEEK_BASED_YEAR );
- LocalDate ld = LocalDate.parse( "2010-12-31" ) ;
- int weekOfWeekBasedYear = ld.get( IsoFields.WEEK_OF_WEEK_BASED_YEAR ) ;
- int yearOfWeekBasedYear = ld.get( IsoFields.WEEK_BASED_YEAR ) ;
- String outputWeek = String.format( "%04d" , yearOfWeekBasedYear ) + "-W" + String.format( "%02d" , weekOfWeekBasedYear ) ;
- String outputDate = outputWeek + "-" + ld.getDayOfWeek().getValue() ;
- YearWeek yw = YearWeek.from( ld ) ; // Determine ISO 8601 week of a `LocalDate`.
- String output = yw.toString() ;
- YearWeek yearWeek = YearWeek.parse( "2010-W52" ) ;
- LocalDate localDate = yw.atDay( DayOfWeek.MONDAY ) ;
Add Comment
Please, Sign In to add comment