Type mismatch: cannot convert from String to Date

0

mam pewien skrypt :

 private Date getLiveDate(DeadPlayer player) {
		if (_plugin.getHardcoreConfiguration().useResurrectionDay) {
			//if they died before the start, they can come back after the start
			if (player.getDeathDate().before(_plugin.getHardcoreConfiguration().resurrectionDayStart))
				return _plugin.getHardcoreConfiguration().resurrectionDayStart;
			//if they died after the start, they can come back at the end
			else
				return _plugin.getHardcoreConfiguration().resurrectionDayEnd;
		} else {
			DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			//wow java date math is a pain
			
			Calendar c = Calendar.getInstance();
			c.setTime(player.getDeathDate());
			c.add(Calendar.SECOND, _plugin.getHardcoreConfiguration().deathSeconds);
		
			return dateFormat.format(c.getTime());
		}

i przy return dateFormat.format(c.getTime());
wyrzuca mi błąd

Type mismatch: cannot convert from String to Date

może wie ktoś jak rozwiązać ten problem?

0

Albo zwracasz Date, wtedy niepotrzebnie robisz format, albo zieniasz typ zwracany na String.

0

albo inaczej to napiszę

 private Date getLiveDate(DeadPlayer player) {
		if (_plugin.getHardcoreConfiguration().useResurrectionDay) {
			//if they died before the start, they can come back after the start
			if (player.getDeathDate().before(_plugin.getHardcoreConfiguration().resurrectionDayStart))
				return _plugin.getHardcoreConfiguration().resurrectionDayStart;
			//if they died after the start, they can come back at the end
			else
				return _plugin.getHardcoreConfiguration().resurrectionDayEnd;
		} else {
			//wow java date math is a pain
			Calendar c = Calendar.getInstance();
			c.setTime(player.getDeathDate());
			c.add(Calendar.SECOND, _plugin.getHardcoreConfiguration().deathSeconds);
			return c.getTime();
		}

w tym skrypcie chce zmienić format daty. Bardzo proszę o pomoc

0

Java nie ma 'skryptow'.
W tym kodzie nie ma ani slowa na temat formatowania - jestes w ogole pewien co chcesz osiagnac?

0

to jest kod w którym próbuję zmienić format daty wysłałem wcześniej kod bez jakichkolwiek moich zmian i się pytam jak można to zrobić :)

0

Nie możesz zmienić formatu daty w funkcji, która zwraca typ Date. To powinna być funkcja, która zwraca String.

1 użytkowników online, w tym zalogowanych: 0, gości: 1