Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    public static String getDayAndMonthFromDateString(String date) {
        java.util.Calendar calendar = getCalendarFromStringDate(date);
        System.out.println("Date ->" + date);
        DateFormatSymbols symbols = new DateFormatSymbols(new Locale("es", "ES"));
        String[] monthNames = symbols.getMonths();

        return calendar.get(java.util.Calendar.DAY_OF_MONTH) + " DE "
                + monthNames[calendar.get(java.util.Calendar.MONTH)];
    }

    public static java.util.Calendar getCalendarFromStringDate(String dateString) {
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        format.setTimeZone(TimeZone.getTimeZone("ETC/UTC"));

        try {
            Date date = format.parse(dateString);
            // System.out.println("Date ->" + date);
            calendar.setTime(date);
            return calendar;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}