Use the SimpleDateFormat class to format the date object into a human-readable format. Joda-Time makes this work much easier. fromJson(JsonStringYouGotSomehow, YourObject. time, the modern Java date and time API. You'd have to supply that information, obviously. Oct 13, 2023 · To convert epoch time to LocalDate, we need to convert the epoch time in milliseconds to an Instant object. you can solve the problem much simple like First convert the the given string to the date object eg: java. toLocalDate(); Nov 5, 2008 · 16. time framework is built into Java 8 and later. May 19, 2009 · The java. Integer. Dec 19, 2010 · Here's another way to convert byte[] to long using Java 8 or newer: private static int bytesToInt(final byte[] bytes, final int offset) {. android. parseLong(str)); to convert your String to Date object. length; return (bytes[offset + Integer. decode () under the hood with one important addition – if the String argument is null, then it returns null. Date, then format the date using SimpleDateFormat using a format pattern matching the input string. Jan 2, 2010 · In case you're not on Java 8 yet, or are forced to use java. DateFormat df = new android. Date createSqlDate(int year, int month, int day) {. And search Stack Overflow for many Apr 28, 2012 · for producing nice time and date and what I'd ultimately like to do is show my resulting currentTimeMillis value into the android. SimpleDateFormat datetimeFormatter1 = new Mar 28, 2018 · If that's the case, you can convert the java. So you first need to multiply it by 1000 to get the timestamp in milliseconds. floatValue(); System. /**. atZone(zoneId). addTo(LocalTime. System. set(2016, 3, 28); c. try this: java. How can I convert this to usefull values like float and int? I tried to cast it but I got java. Please check at the top of the class. Using the new Date/Time API available since Java 8: Feb 22, 2015 · Due to some clueless soul, we have several fields in a legacy database that uses a 6-digit integer to represent a date in (YYYYmm) format. my long value is strDate1="1346524199000" please help me Nov 4, 2011 · In case you're restricted to legacy java. of( "Europe/Amsterdam" ); LocalDate date = Instant. getTime() method Syntax: public long getTime() Parameters: The function do May 20, 2014 · I'm finding a way to store "083752" value (timestamp value in long data format) to Mysql database (type = DateTime). Dec 27, 2023 · Converting a long to a date in Java is a simple task. Date to java. Type mismatch: cannot convert from long to DateFormat Jan 8, 2024 · Moreover, convеrting thеsе timеstamp strings to long valuеs is crucial for performing datе and timе-rеlatеd opеrations in Java. Convert the given date into a string using format () method. getTime(); Still, be careful because in Java the milliseconds obtained are the milliseconds between the desired epoch and 1970-01-01 00:00:00. Steps: Step 1: Create current date and time using ZonedDateTime. ofEpochMilli(timestampInMillis) mеthod to convеrt thе Long timеstamp into an Instant. And search Stack Overflow for many examples Jan 1, 1970 · The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). To convert it to a Java Date instantiate a new Date Object (see Java doc) and invoke setTime() on that. BYTES <= bytes. format(from); Nov 27, 2020 · There are basically three methods to convert long to int: By type-casting. google. // 1 - create DateTime from the long. println("long value: " + value1); System. Date(sqlDate. Using Joda-Timе Mar 19, 2013 · As the first answer says. Instant class or the java. This is sent from my services to the front end which displays it in the format: date:'dd/MM/yyyy' using AngularJS. Date; 2. I use following code to do that. Parameters: date - the milliseconds since January 1, 1970, 00:00:00 GMT. parse(dt); Java can't just look in a crystal ball and figure out you want 22:01:00. What you do want to be careful about is not calling constructors of the boxed primitive classes - that can be wasteful. Aug 3, 2021 · parse the new string. toIntExact(number); 2. Nov 4, 2014 · Using SimpleDateFormat on Java 7 or newer. Calendar, & java. Jan 1, 2011 · The java. format(value. setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"). parse("Tue Mar 19 00:41:00 GMT 2013"); Then use that to format the resulting date object with another instance of SimpleDateFormat like this: String to = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"). Date represents an instant on the time-line, not a "date". longValue() answered Mar 27, 2018 at 11:36. // Create a date string with leading zeros for month and Oct 11, 2021 · DateTime dt= new DateTime(toDateString); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateTime result=formatter. ENGLISH); Date date = format. Getting the default time zone so we can append the timezone info with the date 2. Calendar, and java. Date, . How can I convert this into Epoch/Unix time? To get a java. ofEpochMilli(dateTime), ZoneId. SimpleDateFormat. Both classes provide a number of methods for converting to other date and time representations. Why the answers posted in 2016 also use the then long outdated classes SimpleDateFormat and Date is a bit more of a mystery to me. Despite its name, java. When we’re converting an Instant object, it’s required to use a ZoneId because Instant objects are time-zone agnostic — just points on the timeline. In your case, LocalDateTime. And search Stack Overflow for many Sep 13, 2015 · 3. time, the modern Date-Time API: Parse the Date-Time string into LocalDateTime. valueOf(long), cast from int to long will be done implicitly in case of using Long. Let’s see how to convert a String into a java. UTC); If the original Date isn’t in UTC, we can provide the offset (stored in a helper Dec 1, 2020 · 2. wrap(byte[]). For the Math package, we can use the toIntExact method: return Math. Oct 6, 2011 · The java. The Joda-Time project, now in maintenance mode, advises migration to the java. Don't convert your ZonedDateTime to a String and back to a LocalDateTime. Convert Long to Date In this section, you will learn to convert a long into a date format. util. Apr 21, 2016 · You can create a Calendar object and then set it's date to the date you want and then call its getTimeInMillis() method. So to convert the LocalDate to Date, we must append the time and timezone info with the date. valueOf () We can use the valueOf () method of the String class to achieve the same goal: May 11, 2024 · Java 8. text. toInstant() . First, you'll have to convert your long to a byte array (not all of that question is relevant to this case, but some of it is -- particularly the part that mentions ByteBuffer). parse(string); Jun 4, 2020 · Type mismatch: cannot convert from java. Use the setTime() method of the Date object to set the time in milliseconds since January 1, 1970, at 00:00:00 GMT. 1. Instead of using (Date)formatter. getInstance(); c. Date - date + time + timezone java. getLong(). The Date class has a constructor that directly accepts a timestamp in milliseconds: public static Date dateFrom(long input) {. Converting Date to OffsetDateTime is pretty simple. import java. Use String. and (long seconds, int nanoseconds) and Date does include a (long) constructor (which creates a date object based of number of seconds from epoch - same as java. Date date1 = new Date("11/19/2015"); SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy HH:mma"); String format = formatter. Here, we can take advantage of a new toInstant() method, which was added to java. LocalDateTime: Introduced in Java 8 as part of the java. lang. Here is an example: 1. valueOf(10000); float value2 = value1. println(f. 3. Step 2: Create a timezone for Los Angeles using ZoneId. Using the Long. Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for Unix time. Use XXX for the timezone in the format string instead of Z:. time, and a nifty diagram, see my Answer to another Question. dateInMs is a long value of DateTime. In Java, we can also convert the object of wrapper class Long into an int. An Instant represents a point on the timeline in the UTC timezone: long epochTimeMillis = 1624962431000L; // Example epoch time in milliseconds Instant instant = Instant. parse(myDate); long millis = date. Date: Feb 11, 2012 · Time zone is critical to parsing a string into a date-time value unless you absolutely sure all the strings represent date-times occurring in the same time zone. Date utilDate = new java. On the other hand, we can use the wrapper class Long to get the int value: Aug 1, 2012 · Possible Duplicate: converting long string to date I need to convert long date value to mm/dd/yyyy format. The Joda-Time project, now in maintenance mode, advises migration to java. if you are using SimpleDateFormat() the format specified as a parameter to this function should match the format of the date in the String (str in your case). sql Jun 27, 2007 · // Here, the important thing to note is that the parts of the date // were correctly interpreted, such as day, month, year etc. format(date)); – Nov 25, 2018 · 2. Java 8 and Beyond TimeZone Conversion. Your input for the Jan 24, 2024 · The Java data type for this count is Long. But when I try to convert it from long data into DateTime in Java, using Date date = new Date(long), it will return = Sun May 06 19:04:17 WIB 272097407 instead. 5,952 2 27 37. DateTime dateFromLong = new DateTime(myLongDateAndTime); // 2 - Format dateFromLong as date string. Calendar c = new Calendar. mmm'Z'"); System. * Create a java. parse(date). from( zdt. 0. time classes. Your value is in seconds, so you need to convert it to milliseconds. It just represents specific instance in time in milliseconds starting from 1970-01-01. parse(value. 7. Stanislav Tsepa. Instead, use what the API provides. Deep. parse(formatter. This custom deserialiser will convert the long value from the json into the defined date format (either Date or String). LocalDate - only date. e. TimeZone classes, which we sometimes still need to work with. DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmXXX"); This works if you are using Java 7 or newer. Apr 16, 2011 · 842. Converting Date to OffsetDateTime. Dec 5, 2010 · For small values, casting is enough: long l = 42; int i = (int) l; However, a long can hold more information than an int, so it's not possible to perfectly convert from long to int, in the general case. Wrapper Class. parseUnsignedLong () Method. parseLong("123") and Long number = Long. It is recommended to stop using them completely and switch to the modern Date-Time API *. Nov 23, 2022 · If we have the Date object of the SQL package, then we can easily convert it into an util Date object. For example, assigning an int value to a long variable. Date; with import java. assert offset + Integer. Let’s see how to do the conversion: long milliSecondsSinceEpoch = 2131242L ; ZoneId zoneId = ZoneId. Note, that setTime expects milliseconds instead of seconds, so you would have to multiply your timestamp by 1000. ofEpochMilli(epochTimeMillis); May 12, 2014 · I have a date (which is a Timestamp object) in a format of YYYYMMDDHHMMSS (e. Both are static methods and call upon String and Long classes directly. These classes supplant the troublesome old legacy date-time classes such as java. Date; - This date has both the date and time in it already. toString()); Remember that Date has no format. Specification is JSR 310. valueOf (String). Using intValue () method of the Long wrapper class. format(date)); Oct 7, 2022 · 2. DateTime dateTime = new DateTime(date); For more info about Joda-Time. println("Date : " +d); But its showing Date : Wed Dec 29 00:28:58 IST 45183249 date which is incorrect and not showing year too. Thanks in advance. Step 3: Create a timezone for Dubai country using ZoneId. Calendar APIs, you need to take into account that the timestamps are interpreted in milliseconds, not seconds. – vpzomtrrfrt. If you have a long milliseconds and want to convert them into date string at specifies time zone and pattern, then you can use it:-. plusMillis(offset); bodyObject. class); Aug 20, 2009 · As soon as there is only method Long. Jul 14, 2011 · About java. now(). of(“UTC”)) method operates to transform thе Instant into a LocalDatеTimе using thе UTC timе zonе. order(ByteOrder. Jan 8, 2024 · We can simply use the toString () method of the Long class to convert them to String: String str2 = Long. We are also going to discuss in-depth how to convert a Long value into a Date value in the Java programming language. DateFormat(); e. DateFormat df = new SimpleDateFormat(pattern); // Get the today date using Calendar object. If the next token is a string, this method will attempt to parse it as a long. ofInstant(instant, ZonеId. First parse your date with SimpleDateFormat like this: Date from = new SimpleDateFormat("E M d hh:mm:ss z yyyy"). LITTLE_ENDIAN). time package, LocalDateTime represents a date-time without a time zone in the ISO-8601 calendar system Sep 16, 2013 · How to convert Large Integer 130552992000000000 into date format? This is today’s date and timestamp. out. This question is a bit old but for those arriving here scratching their heads because their Timestamp object does not include a (long) constructor, Firebase's com. Date tells that you have imported a wrong Date object. MAX_VALUE you can convert it by casting without losing any information. time } And to convert Documentation: "Returns the long value of the next token, consuming it. Date class. Date from from year, month, and day of the month. format(date); System. If the long holds a number less than or equal to Integer. May 7, 2023 · Method 1: Using DateFormat. Convert a Date to a String using DateFormat#format method: String pattern = "MM/dd/yyyy HH:mm:ss"; // Create an instance of SimpleDateFormat used for formatting. firebase. Explore Teams Create a free Team fun convertLongToTime(time: Long): String { val date = Date(time) val format = SimpleDateFormat("yyyy. Mar 25, 2015 · Use Date date =new Date(Long. " – Long value1 = Long. Date from year, month, and day. */. atZone(ZoneId. The date field is assumed to be the last day of the given month. Create an instance of the java. Edit: More precise math Oct 7, 2011 · So Long number = Long. Date, Calendar, & SimpleDateFormat. Date myDate = new java. getDate(); How should I convert this long value to String? Also I want to convert back to long from String. I am new to Java and Blackberry development. BYTES - 1] & 0xFF) |. Instead I do as Amongalen suggested in a comment, I am using java. Dec 20, 2011 · i am tring to convert string in format of dd/mm/Y to date but when i convert, no matter what date i choose, it returns day as 27, month and year are correctly returned. Represent the span of time as a Duration object. float value: 10000. Given below are the Java programs for getting the current date and time and printing in a given format. Edit: For comparison Calendar has millisecond resolution, so would at best give you a substabtial loss of precision. I think it's what you want: DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss. parse(date. dd HH:mm") return df. Using Explicit Type Casting. Create an instance of SimpleDateFormat class to format the string representation of the date object. DateTimeFormatter. println(date. time. How to do the latter correctly can be found here. Jan 10, 2024 · Before diving into the conversion: Long: In Java, a long value representing time usually stands for the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 GMT). Your link says the opposite, that double to long is a narrowing conversion, while long to double is widening. The following coding i have written. format(timestamp)); Now at my service end I want to convert this timestamp into "Long" data type for my further processing. Jan 8, 2024 · 3. and here is how you can do that: public DateTime combineDates(long myLongDateAndTime, String myStringTime) {. createLong( "0x80000000" ); It uses Long. The more clear way to do this is. println(dateFormat. atOffset(ZoneOffset. That's the standard way of representing dates. Apr 15, 2024 · Java Convert long timestamp to a Date. Since Java 8, we can use two more ways to do type conversion: using the Math package or using a lambda function. long seconds = 1320105600; long millis = seconds * 1000; Jan 8, 2024 · Morеovеr, we utilize the Instant. println( number - (long) converted); answered Aug 19, 2018 at 7:39. Get the date using the Calendar object. parseString("123") all end up doing pretty much the same thing. Jan 1, 2013 · The java. I tried with. toString());, try formatter. The toString() method yields something readable. getNano(); Unfortunately, the total number of nanoseconds will be too big to fit in a long, so you 2. Feb 17, 2022 · java. getTimeInMillis(); If you want to convert the String directly into the date you can try this: That timestamp contains the seconds elapsed since 1970-1-1 0:00 UTC. For instance, considеring thе timеstamp string 2023-11-15 01:02:03, thе rеsulting long valuе would bе 1700010123000L, rеprеsеnting thе numbеr of millisеconds sincе January 1, 1970, 00:00:00 GMT May 24, 2011 · It looks like the code in the original question was intended not only to convert Date to Calendar, but also to remove the time from the date at the same time. – Viddyut Khanvilkar Commented May 18, 2021 at 7:10 Example 3: Convert object of the Long class to int. getTime()); It will give us util Date object. return new Date (input); } With Calendar, we have to call setTimeInMillis () after getInstance (): public static Calendar calendarFrom(long input) {. The actual data stored within the object is a long count of milliseconds since 1970-01-01T00:00Z (midnight at the start of Dec 28, 2023 · 1. ISO_LOCAL_TIME. I am writing a back-end service and receive timestamp as shown below. ofPattern("yyyy-MM-dd HH:mm:ss") Jul 16, 2018 · And for converting the bytes data into long data, I'm using this code : ByteBuffer. Happy Coding 😊. I have declare the date for date1 is: 7-11-11 12:13:14. Approach: Get the date to be converted. Java provides some methods and APIs to solved it. private java. ofInstant seems to be just what you need: LocalDateTime localDateTime = LocalDateTime. format () method. Jan 7, 2009 · Since your double represents the number of seconds of you date from now, and the Date constructor in Java is expecting a number of milliseconds since 01-01-1970, you have to multiply your number to get a number of milliseconds (* 1000) and substract that from the current number of milliseconds since 01-01-1970 (System. We can directly assign a timestamp object to a date instance to convert a timestamp to a date. midnight). toString()); Edit What i need to do is 83752 => 1/2/1970 4:45:52 AM Java examples of converting a long value to a String in two different ways. Duration. Jan 8, 2024 · Before Java 8, our simplest options were Date and Calendar. Quick Reference. systemDefault()); Aside from that, you meantioned that the timestamp Mar 15, 2023 · If the data types are compatible, then Java will perform the conversion automatically known as Automatic Type Conversion, and if not then they need to be cast or converted explicitly. Mar 7, 2013 · 12. Instant timestamp = Instant. currentTimeMillis()): Jan 8, 2024 · Let’s start with converting the old date representation to the new one. Date taking the date as a long argument interprets the argument in milliseconds, not seconds. DateFormat df = currentTimeMillis(); when I try I get. Solution using java. Bits Acquired In Memory. Jan 17, 2022 · If we have the Date object of the SQL package, then we can easily convert it into an util Date object. If you have two String objects, where 1 holds the Date and the other Time, you can combine the 2 Strings and Aug 23, 2014 · 26. util Date-Time API and their formatting API, SimpleDateFormat are outdated and error-prone. // the string representation of date according to the chosen pattern. Please stop using SimpleDateFormat. To learn more, see the Oracle Tutorial. boolean. In Java, you can convert a long value representing a date in milliseconds to a Date object with the “dd/MM/yyyy” format using the SimpleDateFormat class. You can achieve the date conversion from long to String or Date by using the custom deserialiser. Using Custom Deserialiser in jackson. In your case yyyy-MM-dd does not match the format of the time stamp (1427241600000). getTime() method Syntax: public long getTime() Parameters: The function do Mar 6, 2019 · The Calendar class that you were trying to use was always poorly designed and is now long outdated. java. You will need to replace import java. Print the result. Date to Instant using toInstant() method, and then get the numerical values from it: Instant instant = date. In this Java core tutorial, we learn how to convert long value into float value in Java via different Apr 30, 2024 · Method 3: Converting a Timestamp to a Date Using a Date Reference. I have written the following method to perform the conversion from int to java. of(0, 0))) Formatters need a temporal object to format, so you can create one by adding the duration to a LocalTime of 00:00 (i. The java. Integer value = 19000101; SimpleDateFormat originalFormat = new SimpleDateFormat("yyyyMMdd"); Date date = originalFormat. Calling atStartOfDay() so Feb 11, 2014 · I want to convert a date to a long value (that is the milliseconds) I have a date like 2/11/2014 I want to calculate the date in long (manual) What I've tried (2014 - 1970 ) * 31449600000 + 11 * Aug 1, 2012 · Java 8, Convert milliseconds long to Date as String by given date format pattern. Date object, go through the Instant. What you get is a long number representing the number of millis elapsed from Jan 1st, 1970. Datatype. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); System. For this, we can use the intValue() method. create(); YourObject parsedObject1 = gson. Keeping this in mind, the steps for the conversion are as follows: 1. Mar 31, 2016 · @Ken Wolf Is it possible to combine two separate Strings, one date String and one time String into one String (for example, "30/09/2014" and "10:00 PM" into "30/09/2014 10:00 PM" to get a long value from the combined String? The date String is format "dd/MM/yyyy" and the time String is format "h:mm a". If our Date is in UTC, we can convert it with a single expression: Date date = new Date (); OffsetDateTime offsetDateTime = date. Here is a quick and easy way to create a java. Sep 16, 2010 · long number = 499999999000000001L; double converted = (double) number; System. Date object: After choosing the date, I need to convert that long value to String, so that I can easily store the date value somewhere in database. 20140430193247). long date = curDateFld. How can I parse it to long? Have I to get the day, parse to long, get the month, parse to long, get the year, parse to long and then concatenate? 1. MM. Using toIntExact () method. Date class represents the date and time elapsed since the epoch. println(format); Mar 1, 2023 · If we have the Date object of the SQL package, then we can easily convert it into an util Date object. In this article, we are about to learn what are Long and Date in Java and their implementation in the Java Programming language. toString () methods. toInstant(); long secondsSinceEpoch = instant. Jan 10, 2024 · The static factory method createLong () converts a String to a Long object: Long l = NumberUtils. ofEpochMilli(milliSecondsSinceEpoch). Date d = new Date(130552992000000000L * 1000); System. 4. long l = 083752; Date date = new Date(l); System. ClassCastException: java. g. Convert the LocalDateTime to Instant. valueOf (), and the second uses Long. You can use SimpleDateFormat to print that date in a cuter way. And search Stack Overflow for many Dec 12, 2012 · In 2012 when the question was asked, the answers also posted back then were good answers. Date, java. dd HH:mm") return format. The constructor of java. 3. It will return the exact long data value as C# did. Plain java Date and Joda-Time DateTime should serve the purpose. It formats a date string and uses Date. valueOf("123"), Long number = Long. There's a fairly simple and (IMO) elegant approach, at least for durations of less than 24 hours: DateTimeFormatter. Date. Date and java. Timestamp object include (Date date) constructor. Float Sep 11, 2022 · java. toInstant() ); For more discussion of converting between the legacy date-time types and java. time, the modern Java date and time API Aug 7, 2012 · The java. For, example, . println("float value: " + value2); } } The output is: long value: 10000. getTime() method Syntax: public long getTime() Parameters: The function do Dec 12, 2014 · I have a String date = dd/MM/yyyy. 2. Jan 20, 2014 · Short answer. Subsеquеntly, thе LocalDatеTimе. Description of program: This example helps you in converting a long value into a Date. sql. now () method. These classes supplant the troublesome old date-time classes such as java. of () method. – Mar 29, 2011 · java. Thus, I need to convert that value to human readable date time. String string = "January 2, 2010"; DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale. ofInstant(Instant. toString(obj); The output will look like this: If our obj object is null, we’ll get a NullPointerException. The getDateInstance() method is a time formatter with the given formatting style for the default locale Jul 11, 2011 · I want to convert string Date into Timestamp in java. valueOf(number); String strValue2 Date d = new Date((long)timestamp*1000); will create a Date instance. toLocalDate(); Explanation. Long cannot be cast to java. long number = 123456789L; String strValue1 = String. Mar 3, 2015 · Ask questions, find answers and collaborate at work with Stack Overflow for Teams. And search Stack Overflow for many examples and explanations. format(date) } fun currentTimeToLong(): Long { return System. If the next token's numeric value cannot be exactly represented by a Java long, this method throws. getEpochSecond(); int nanoSeconds = instant. Displaying it later is another thing. Date in Java 8. And search Stack Overflow for many Mar 17, 2024 · Before Java 8, the Java date and time mechanism was provided by the old APIs of java. Date; Dec 28, 2017 · SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = sdf. Date utilDate = java. lastModified()); and now you have a Date object at hand. println("Date, with the default formatting: " + startDate); // Once converted to a Date object, you can convert // back to a String using any desired format. Timestamp;import java. format(date)); Aug 12, 2019 · In Java, longs have 64-bits (and one of those bits is used for the sign), so you can indeed have 8 chunks of 8-bit long characters. Aug 12, 2010 · The java. valueOf(Long. The two most common ways to do this are to use the java. We need to pass the getTime() method while creating the util Date object. Date input = new Date(); LocalDate date = input. ISO_INSTANT. The first example uses String. toInstant(). Example to convert the current date and time to one timezone to another timezone. systemDefault()). Date(theFile. Here is an example of how to convert an epoch timestamp to a date in Java: java import Quite literally if you already have an Date object with the name "created_at" in the class you are creating then it is this easy: Gson gson = new GsonBuilder(). put("timestamp", DateTimeFormatter. Finally, we also need to know the timezone. currentTimeMillis() } fun convertDateToLong(date: String): Long { val df = SimpleDateFormat("yyyy. In typing casting, a data type is converted into another data type by the programmer using the casting operator during the program design. First you have to parse your format into date object using formatter specified. Date date = new Date(); // java. format. valueOf(intValue). ej gj vt vk ud hj wx ej zl zl