Yuav Ua Li Cas Hloov Cov Hlua Rau Hnub Tim

Cov txheej txheem:

Yuav Ua Li Cas Hloov Cov Hlua Rau Hnub Tim
Yuav Ua Li Cas Hloov Cov Hlua Rau Hnub Tim

Video: Yuav Ua Li Cas Hloov Cov Hlua Rau Hnub Tim

Video: Yuav Ua Li Cas Hloov Cov Hlua Rau Hnub Tim
Video: Yuav ua li cas thiaj khiav dim lub ntiajteb no 2024, Hlis ntuj nqeg
Anonim

Hloov txoj hlua khi rau hnub tim yog ib txoj haujlwm ib txwm ua ntawm tus programmer ntsib thaum sau qee yam program lossis sau ntawv. Txhua hom lus siv txoj haujlwm no rau nws tus kheej txoj kev thiab nws muaj nws cov cuab yeej los ua cov ntaub ntawv hom xov xwm.

Yuav ua li cas hloov cov hlua rau hnub tim
Yuav ua li cas hloov cov hlua rau hnub tim

Cov Lus Qhia

Kauj ruam 1

Lub sijhawm Delphi programmes siv StrToDate () kev ua haujlwm los hloov txoj hlua rau hnub, thiab txoj hlua yuav tsum yog "tus lej xov tooj" hom. Lub HnubToStr () kev ua haujlwm yog lub luag haujlwm rau qhov thim rov qab. Yog tias koj xav hloov hnub tim ntawm hom ntawv "Lub Ib Hlis 01, 2000", tom qab ntawv koj yuav tsum hloov tus nqi ntawm lub hlis mus rau tus lej, thiab tom qab ntawd nqa tawm cov txiaj ntsig siv cov haujlwm tsim nyog.

Kauj ruam 2

C # tseem siv txoj haujlwm sib xws. Piv txwv li, yog hnub tim nyob rau hauv hom "Sat, 01 Jan 2000", tom qab ntawd koj tuaj yeem siv tus qauv Convert. ToDate () lossis Date. Parse () ua haujlwm.

Kauj ruam 3

PHP muaj kev ua haujlwm tshwj xeeb strtotime (). Piv txwv, cov lus nug "echo strtotime (" 01 Lub Ib Hlis 2000 ");" yuav hloov txoj hlua tshwj xeeb rau hnub thiab muab tso rau ntawm qhov screen. Yog tias koj xav tau txhais ib txoj hlua xws li "01012001" rau hauv cov hnub tim raug, ces nws yog qhov zoo uas yuav tau siv cov kab lus niaj zaus:

muaj nuj nqi string_and_time ($ sijhawm) {

rov qab mus preg_replace (“/ (d {2}) (d {2}) (d {4}) / e”,”\ '. match_month (' / 2’). '\ 3”, $ sijhawm); }

echo string_and_time (01012001);

Kauj ruam 4

Rau C ++, muaj sscanf () muaj nuj nqi uas ua qhov tsim nyog hloov dua siab tshiab. Yog tias koj siv Qt4 lub tsev qiv ntawv, koj tuaj yeem siv txoj haujlwm "QDate:: fromString (" 01.01.2001 "," dd. MM.yyyy ")".

Kauj ruam 5

Rau Pascal, txoj haujlwm StrToDate () tuaj yeem yooj yim kho cov kev hloov pauv ntawm cov hlua mus rau hnub, tab sis yog tias koj qhov kev zov me nyuam siv cov npe ntawm lub hli, koj yuav tsum siv VarToDateTime ():

var

DateOne, HnubTxoj, HnubTxawm: TDateTime;

Pib

DateOne: = VarToDateTime ('Lub Ib Hlis 1, 2000');

ShowMessage (DateToStri (DateOne));

xaus;

Kauj Ruam 6

Hauv Java, koj tuaj yeem siv cov ntawv sau hauv qab no los hloov pauv:

Java.lang. Integer:

Hlua myString = “1”;

Rau kuv = Integer.parseInt (myString);

Java.text. DateFormat:

HnubFormat formDate = DateForman.getDateInstance ();

Java.util. Date:

Hnub tim pebDate = dateFormat.parse (“01.01.2000”);

Pom zoo: