Java Code Examples for java.util.Date.getDate()

The following are Jave code examples for showing how to use getDate() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: ZioEntry.java   View Source Code Vote up 8 votes
public void setTime(long time) {
    Date d = new Date(time);
    long dtime;
    int year = d.getYear() + 1900;
    if (year < 1980) {
        dtime = (1 << 21) | (1 << 16);
    }
    else {
        dtime = (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
        d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
        d.getSeconds() >> 1;
    }

    modificationDate = (short)(dtime >> 16);
    modificationTime = (short)(dtime & 0xFFFF);
}
 
Example 2
Project: LJFramework   File: TimeUtils.java   View Source Code Vote up 6 votes
/**
 * 获取当天的下一个月
 */
public static String getNextMonth() {
    Date t = new Date();
    String nmonth = new String();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    try {
        //t=sdf.parse(now);
        Date nextmonth = new Date((t.getYear() + (t.getMonth() + 1) / 12),
                (t.getMonth() + 1) % 12, t.getDate());
        nmonth = sdf.format(nextmonth.getTime());
    } catch (Exception e) {

        e.printStackTrace();
    }
    return nmonth;
}
 
Example 3
Project: ImageClassify   File: CalendarView.java   View Source Code Vote up 6 votes
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Date date = getItem(position);
    if (convertView == null) {
        convertView = layoutInflate.inflate(R.layout.calendar_day_item, parent, false);
    }
    int day = date.getDate();
    ((TextView) convertView).setText(String.valueOf(day));
    boolean isTheSameMonth = false;
    if (date.getMonth() == selectedDate.getMonth()) {
        isTheSameMonth = true;
    }
    if (isTheSameMonth) {
        ((CalendarDayTextView) convertView).setTextColor(Color.parseColor("#000000"));
    } else {
        ((CalendarDayTextView) convertView).setTextColor(Color.parseColor("#666666"));
    }
    //判断当前日期是否是已签到的日期
    if (daySet.size()>0  && daySet.contains(((TextView) convertView).getText()) && isTheSameMonth) {
        ((CalendarDayTextView) convertView).isSelected = true;
    }
    return convertView;
}
 
Example 4
Project: calendar-component   File: SimpleDayCell.java   View Source Code Vote up 6 votes
@SuppressWarnings("deprecation")
public void setDate(Date date) {
    int dayOfMonth = date.getDate();
    if (monthNameVisible) {
        caption.setText(dayOfMonth + " " + calendar.getMonthNames()[date.getMonth()]);
    } else {
        caption.setText("" + dayOfMonth);
    }

    if (dayOfMonth == 1) {
        addStyleName("firstDay");
    } else {
        removeStyleName("firstDay");
    }

    this.date = date;
}
 
Example 5
Project: healthgo   File: DateTimeHelper.java   View Source Code Vote up 5 votes
public static String[] get6days(boolean returnString)
{
    Date d=getToday();


    String [] days=new String[6];
    for (int i=0;i<6;i++)
    {
        Date t=add(d,i-5);
        days[i]=t.getMonth()+1+"."+t.getDate();
    }
    return days;
}
 
Example 6
Project: My-Blog   File: DateKit.java   View Source Code Vote up 5 votes
public static boolean isToday(Date date) {
    Date now = new Date();
    boolean result = true;
    result &= date.getYear() == now.getYear();
    result &= date.getMonth() == now.getMonth();
    result &= date.getDate() == now.getDate();
    return result;
}
 
Example 7
Project: smile_1.5.0_java7   File: DateFeature.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("deprecation")
public double[] feature(Date date) {
    double[] x = new double[types.length];
    for (int i = 0; i < types.length; i++)
    switch (types[i]) {
        case YEAR:
            x[i] = 1900 + date.getYear();
            break;
        case MONTH:
            x[i] = date.getMonth();
            break;
        case DAY_OF_MONTH:
            x[i] = date.getDate();
            break;
        case DAY_OF_WEEK:
            x[i] = date.getDay();
            break;
        case HOURS:
            x[i] = date.getHours();
            break;
        case MINUTES:
            x[i] = date.getMinutes();
            break;
        case SECONDS:
            x[i] = date.getSeconds();
            break;
        default:
            throw new IllegalStateException("Unknown date feature type: " + types[i]);
    }
    return x;
}
 
Example 8
Project: healthgo   File: WeatherChartView.java   View Source Code Vote up 5 votes
public static String[] get6days(boolean returnString)
{
    Date d=getToday();

    String [] days=new String[6];
    for (int i=0;i<6;i++)
    {
        Date t=add(d,i-2);
        days[i]=t.getMonth()+1+"."+t.getDate();
    }
    return days;
}
 
Example 9
Project: openjdk-jdk10   File: bug4100311.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
public static void main(String args[])
{
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 1997);
    cal.set(Calendar.DAY_OF_YEAR, 1);
    Date d = cal.getTime();             // Should be Jan 1
    if (d.getMonth() != 0 || d.getDate() != 1) {
        throw new RuntimeException("Date isn't Jan 1");
    }
}
 
Example 10
Project: PaySim   File: ParameterizedPaySim.java   View Source Code Vote up 5 votes
private void initSimulatorName(){
	Date d = new Date();
	ParameterizedPaySim.simulatorName = "PS_" + (d.getYear() + 1900) + (d.getMonth() + 1)  + d.getDate() + d.getHours() + d.getMinutes()
			+ d.getSeconds() + "_" + this.seed;
	//System.out.println(simulatorName + "\n");
	File f = new File(System.getProperty("user.dir")  +"//outputs//" + ParameterizedPaySim.simulatorName);
	f.mkdir();
}
 
Example 11
Project: jdk8u-jdk   File: ZipUtils.java   View Source Code Vote up 5 votes
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 12
Project: jdk8u-jdk   File: ZipUtils.java   View Source Code Vote up 5 votes
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 13
Project: uavstack   File: DateTimeHelper.java   View Source Code Vote up 5 votes
/**
 * 测试是否是当天
 * 
 * @param date
 *            某一日期
 * @return true 今天, false-不是
 */
@SuppressWarnings("deprecation")
public static boolean isToday(Date date) {

    Date now = new Date();
    boolean result = true;
    result &= date.getYear() == now.getYear();
    result &= date.getMonth() == now.getMonth();
    result &= date.getDate() == now.getDate();
    return result;
}
 
Example 14
Project: calendar-component   File: DateCellDayItem.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
private long calculateStartFromMinute(long startFromMinutes, Date from,
        Date to, int dayOffset) {
    boolean eventStartAtDifferentDay = from.getDate() != to.getDate();
    if (eventStartAtDifferentDay) {
        long minutesOnPrevDay = (getTargetDateByCurrentPosition(dayOffset)
                .getTime() - from.getTime()) / DateConstants.MINUTEINMILLIS;
        startFromMinutes = -1 * minutesOnPrevDay;
    }

    return startFromMinutes;
}
 
Example 15
Project: healthgo   File: DateTimeHelper.java   View Source Code Vote up 4 votes
public static Date getToday()
{
    Date d=new Date();
    return new Date(d.getYear(),d.getMonth(),d.getDate());
}
 
Example 16
Project: openjdk-jdk10   File: CompilationStatistics.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
public static void clear(String dumpName) {
    try {
        ConcurrentLinkedDeque<CompilationStatistics> snapshot = list;
        long snapshotZeroTime = zeroTime;

        list = new ConcurrentLinkedDeque<>();
        zeroTime = System.nanoTime();

        Date now = new Date();
        String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes();

        dumpCompilations(snapshot, dumpName, dateString);

        try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) {

            long[] timeSpent = new long[10000];
            int maxTick = 0;
            for (CompilationStatistics stats : snapshot) {
                long start = stats.startTime - snapshotZeroTime;
                long duration = stats.duration;
                if (start < 0) {
                    duration -= -start;
                    start = 0;
                }

                int tick = (int) (start / RESOLUTION);
                long timeLeft = RESOLUTION - (start % RESOLUTION);

                while (tick < timeSpent.length && duration > 0) {
                    if (tick > maxTick) {
                        maxTick = tick;
                    }
                    timeSpent[tick] += Math.min(timeLeft, duration);
                    duration -= timeLeft;
                    tick++;
                    timeLeft = RESOLUTION;
                }
            }
            String timelineName = System.getProperty("stats.timeline.name");
            if (timelineName != null && !timelineName.isEmpty()) {
                out.printf("%s%c", CSVUtil.Escape.escape(timelineName), CSVUtil.SEPARATOR);
            }
            for (int i = 0; i < maxTick; i++) {
                out.printf("%d%c", normalize(timeSpent[i]), CSVUtil.SEPARATOR);
            }
            // print last column
            out.printf("%d", normalize(timeSpent[maxTick]));
            out.println();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Project: acmeair   File: FlightService.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
protected boolean inOneDay(Date date1, Date date2) {
    return (date1.getYear() == date2.getYear()) && (date1.getMonth() == date2.getMonth())
            && (date1.getDate() == date2.getDate());
}
 
Example 18
Project: jdk8u-jdk   File: Bug6772689.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
Example 19
Project: openjdk-jdk10   File: Bug6772689.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
Example 20
Project: calendar-component   File: DateConstants.java   View Source Code Vote up 4 votes
public static CalDate toRPCDate(Date date) {
    return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}