Java SimpleDateformatter with 10 decimals after the seconds, cannot convert to Date

Java SimpleDateformatter with 10 decimals after the seconds, cannot convert to Date

Content Index :

Java SimpleDateformatter with 10 decimals after the seconds, cannot convert to Date
Tag : java , By : Novi Indrayani
Date : November 25 2020, 07:06 PM

Hope this helps There are multiple problems at the moment. I'd strongly recommend using java.time for as much work as possible, although even that doesn't make this easy.
As you say, your value has 10 digits for "fraction of a second" - which means it goes down to 10th-of-a-nanosecond precision. That's highly unusual to start with, in my experience - and I don't think Java can handle that, even with java.time.
// Note this only has 9 digits of precision, not the original 10
String text = "2018-11-02 6:05:59.154116215 PM";
ZoneId zone = ZoneId.of("Asia/Colombo");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
    "yyyy-MM-dd h:mm:ss.SSSSSSSSS a", Locale.US)
ZonedDateTime parsed = ZonedDateTime.parse(text, formatter);
Date date = Date.from(parsed.toInstant());

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to convert a String with decimals to BigDecimal and keep the decimals, in Talend Java?

Tag : java , By : user142345
Date : March 29 2020, 07:55 AM
will help you I'm creating a Job in Talend to transform data from a .csv file using some data from a database and then incorporate into another .csv file. During the transformation some calculation is needed to be performed on the values: , You can use BigDecimal
BigDecimal v1 = new BigDecimal("15.25");
BigDecimal v2 = new BigDecimal("5.25");
BigDecimal v3 = new BigDecimal("1.15");

BigDecimal v123 = v1.divide(v2, MathContext.DECIMAL64).multiply(v3);

System.out.println(v123.setScale(2, RoundingMode.HALF_UP));
double v1 = 15.25;
double v2 = 5.25;
double v3 = 1.15;
double v123 = v1 / v2 * v3;
System.out.printf("%.2f%n", v123);

How to convert decimal timestamp to date in Java with trailing decimals

Tag : java , By : Sebastian Gift
Date : March 29 2020, 07:55 AM
I hope this helps you . I have been trying to figure out how to convert a timestamp to a date but with the trailing decimals at the end, so for example: Timestamp - C50204EC EC42EE92 is equivalent to Sep 27, 2004 03:18:04.922896299 UTC. , java.time
Using the example from the explanation:
    Instant epoch = OffsetDateTime.of(1900, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();

    BigInteger timeStamp = new BigInteger("C50204ECEC42EE92", 16);

    // To get the whole part and the fraction right, divide by 2^32
    double secondsSince1900 = timeStamp.doubleValue() / 0x1_0000_0000L;

    // Convert seconds to nanos by multiplying by 1 000 000 000
    Instant converted = epoch.plusNanos(Math.round(secondsSince1900 * 1_000_000_000L));
    BigDecimal timeStamp = new BigDecimal(new BigInteger("C50204ECEC42EE92", 16));

    // To get the whole part and the fraction right, divide by 2^32
    BigDecimal bit32 = new BigDecimal(0x1_0000_0000L);
    BigDecimal secondsSince1900 = timeStamp.divide(bit32);

    // Convert seconds to nanos by multiplying by 1 000 000 000; round to long
    long nanosSince1900 = secondsSince1900.multiply(new BigDecimal(TimeUnit.SECONDS.toNanos(1)))
            .setScale(0, RoundingMode.HALF_UP)

    Instant converted = epoch.plusNanos(nanosSince1900);

Convert Epoch seconds to date and time format in Java

Tag : java , By : pjkinney
Date : March 29 2020, 07:55 AM

Code to convert seconds to Date and time combination in java

Tag : java , By : Waynew
Date : March 29 2020, 07:55 AM

Convert LocalTime for given zone to unix epoch seconds without the date component in java

Tag : java , By : user158193
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • How to make a GitHub GraphQL API Call from Java
  • What's the difference between @ComponentScan and @Bean in a context configuration?
  • Expected class or package adding a view using a class
  • can be delete of a element in a static array be O(1)?
  • Instance variable heap or stack ? ( with specific example)
  • Assert progress of ProgressBar in Espresso test
  • How to detect if gson.fromjson() has excess elements
  • I cant generate the proper code to select the a specific filter on a BI dashboard I am working on
  • How to Inject Dependencies into a Servlet Filter with Spring Boot Filter Registration Bean?
  • Thrift types as a Generic
  • Effective algorithm to random 4 unique integers less than a big max such as 100_000
  • Combining or and negation in Java regex?
  • Unable to instantiate default tuplizer Exception
  • Multi-tenant migration to work with quarkus
  • Ignite persisting a Set: Cannot find metadata for object with compact footer
  • Maven cannot resolve Jacob dependency using eclipse
  • testcontainers oracle database container starts before database user is created
  • Launching two spring boot apps in integration test
  • Is there a way to add a HashMap's value that is a integer array into a ArrayList?
  • Is there any way that I can get a parameter in paintComponent?
  • Empty stack with one recursive method and one iterative method
  • What's the behavior of onBackpressureBuffer in RxJava2
  • Java regex can only use 1 quantifier in a lookback (need 2)
  • How to fix error in native query : it is showing syntax error near or at
  • How to retrieve nested object from a document and display it in FirestoreRecyclerOptions?
  • Why not use ListIterator for full LinkedList Operation?
  • Android Webview EvaluateJavascript sometimes does not return a response
  • Matcher java doesn't work but regex seems to be good
  • Finding dimensions of a .gif file
  • Java Number format how to change +/- sign to custom text
  • Entity partially saved when using JOINED inheritance strategy and setting spring.jpa.properties.hibernate.jdbc.batch_siz
  • Stored Procedure in Java Spring Boot Project returns null as Output
  • How to solve org.hibernate.MappingException which is causing due to inheriting a class
  • Clean Archtecture. Understanding of scheme
  • Processing 3 triangle not showing in Javafx 8 Window tab
  • How to specify a sequence-based generated value in Hibernate 5 via legacy mapping
  • Spring-boot application not getting auto-deployed on startup
  • How to only pass strings that the user select
  • Is there a way to SELECT using "GREATEST(field1, field2)" where field1 and field2 are aggregate sums in the sa
  • How to handle JSON objects wrapped into one JSON object with retrofit2?
  • Configure Hazelcast CPSubsystem Retries Timeout
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com