Where can I find LocalDate class in Xamarin Android (since Date() is deprecated)

Jeroen B 56 Reputation points
2021-04-25T10:39:47.857+00:00

Hi,
After upgrading my Xamarin project we are getting compile warnings of deprecated Date() class constructor. I want to replace it with Android LocalDate (https://developer.android.com/reference/java/time/LocalDate), is that possible ?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,756 Reputation points
    2021-04-26T02:36:34.907+00:00

    Hello,

    Welcome to Microsoft Q&A!

    LocalDate is not available in Xamarin.Android , as Android suggested ,we could use Calendar class to replace Date class .

    As of JDK 1.1, the Calendar class should be used to convert between dates and time fields and the DateFormat class should be used to format and parse date strings. The corresponding methods in Date are deprecated.

    Date(int year, int month, int date)
    This constructor is deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).

    Date(int year, int month, int date, int hrs, int min)
    This constructor is deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date, hrs, min) or GregorianCalendar(year + 1900, month, date, hrs, min).

    Date(int year, int month, int date, int hrs, int min, int sec)
    This constructor is deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date, hrs, min, sec) or GregorianCalendar(year + 1900, month, date, hrs, min, sec).

    Date(String s)
    This constructor is deprecated. As of JDK version 1.1, replaced by DateFormat.parse(String s).

    Best Regards,
    Cole Xia


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.