Cov txheej txheem:

Koj ua sijhawm li cas hauv Java?
Koj ua sijhawm li cas hauv Java?

Video: Koj ua sijhawm li cas hauv Java?

Video: Koj ua sijhawm li cas hauv Java?
Video: kheev lam sij hawm tig tau rov qab 10/23/2018 2024, Kaum ib hlis
Anonim

Tau txais hnub tim thiab sijhawm tam sim no: java. ntawv nyeem. SimpleDateFormat

  1. ntshuam java ua .text. SimpleDateFormat;
  2. ntshuam java ua .util. Date;
  3. public class CurrentDateTimeExample2 {
  4. public static void main(String args) {
  5. SimpleDateFormat formatter = tshiab SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
  6. Hnub tim = new Date();

Ib yam li ntawd, tib neeg nug, ua li cas koj ntxiv lub sijhawm nyob hauv Java?

  1. import java. siv. Hnub tim;
  2. import java. sql ua. Daim ntawv teev sijhawm;
  3. pej xeem static void main(String args)
  4. Hnub tim = new Date();
  5. ntev = date. getTime();
  6. Qhov system. tawm. println("Lub Sijhawm hauv Milliseconds: " + sijhawm);
  7. Timestamp ts = new Timestamp(time);
  8. Qhov system. tawm. println("Tam sim no lub sij hawm Stamp: " + ts);

Tsis tas li ntawd, dab tsi yog hnub yooj yim hom ntawv? SimpleDateFormat yog ib hoob pob zeb rau formatting thiab parsing hnub nyob rau hauv ib cheeb tsam-sensitive yam. Nws tso cai rau formatting ( hnub -> ntawv), parsing (text -> hnub ), thiab normalization. SimpleDateFormat tso cai rau koj los pib los ntawm kev xaiv cov qauv uas tus neeg siv tau teev tseg rau hnub - sij hawm formatting.

Ntawm no, kuv tuaj yeem tau txais hnub tim thiab sijhawm tam sim no hauv Android li cas?

Tau txais lub sijhawm tam sim no

  1. * Default lub sij hawm format.
  2. pej xeem zoo li qub kawg String DATE_FORMAT_1 = "hh:mm a";
  3. pej xeem zoo li qub String getCurrentTime() {
  4. SimpleDateFormat dateFormat = tshiab SimpleDateFormat(DATE_FORMAT_1);
  5. dateFormat. setTimeZone(TimeZone.
  6. Hnub no = Calendar. getInstance().
  7. rov qab dateFormat. hom ntawv (hnub no);
  8. }

Kuv yuav tau txais 24 teev ntawm kuv lub Android li cas?

Yuav hloov koj lub moos Android li cas rau 24-teev sijhawm

  1. Qhib cov chaw hauv koj lub xov tooj.
  2. Scroll down thiab coj mus rhaub General Management.
  3. Coj mus rhaub Hnub thiab sijhawm.
  4. Coj mus rhaub lub toggle ntawm Siv 24-teev hom ntawv.

Pom zoo: