Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    public static String getLeftDay(String date) {
        if ("".equals(date) || date == null) {
            return "";
        }
        Date cur = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", getLocale());
        String curTime = sdf.format(cur);

        Date dt = new Date();
        long day = 0;
        try {
            dt = sdf.parse(curTime);
            long l = Long.parseLong(date) - dt.getTime();
            if (l > 0) {
                day = l / (24 * 60 * 60 * 1000);
            } else {
                day = 0;
            }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        return Long.toString(day);
    }

    public static Locale getLocale() {
        return Locale.ENGLISH;
    }
}