• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Facing in Date time formatter

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Team

As a beginner in java ,i am following Jeanne Boyarsky, Scott Selikoff-OCA_ Oracle Certified Associate Java SE 8 Programmer I Study Guide_ Exam 1Z0-808-Sybex (2014),

on page 148 till the need of chapter 3,i a not able to execute the code in Command prompt ,i have  jdk 8.0_101.

import java.time.*;

class example{

public static void main(String args[])
{
LocalDate date = LocalDate.of(2020, Month.JANUARY, 20);
LocalTime time = LocalTime.of(11, 12, 34);
LocalDateTime dateTime = LocalDateTime.of(date, time);System.out.println(date
.format(DateTimeFormatter.ISO_LOCAL_DATE));
System.out.println(time.format(DateTimeFormatter.ISO_LOCAL_TIME));
System.out.println(dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));

}
}



3 Errors :can not find the symbol DateTimeFormatter

i import the package as well;

i do not know why it is not working,and the following above program is copy paste from the book .no editing

Please help me ,so that i can move to next chapter.
 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.time.*; imports types which are in the package java.time but class DateTimeFormatter is in the package java.time.format so you need to import DateTimeFormatter  from It like
 
Harshal Sood
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Patekar wrote:import java.time.*; imports types which are in the package java.time but class DateTimeFormatter is in the package java.time.format so you need to import DateTimeFormatter  from It like



Thanks a lot Ganesh Patekar

So,if we have to use a wild card ,then it is like that

import java.time.format.*;

Please revert if it is wrong/some thing else.
 
Ranch Hand
Posts: 145
4
Hibernate Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harshal,

3 Errors :can not find the symbol DateTimeFormatter  



Error is clearly saying you didn't import the package where DateTimeFormatter   is available in your program.



You imported only java.time package. But DateTimeFormatter  is not available in java.time package. It is in java.time.format package . Just add the below line in your import section

. It works fine.

I want to add one more point. If you import like java.time.*; ,  Java imports only classes, interfaces,etc in java.time package only. Java doesn't import classes, interfaces,etc in sub packages of  java.time package.

Hope this helpful !
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Harshal Sood wrote:So,if we have to use a wild card ,then it is like that

import java.time.format.*;  

Yes correct, rest Narayana explained very well
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic