String转Date类型 取当前时间

String转Date类型 取当前时间,第1张

Date date = new Date(); // 这个date里就是当前时间

Date里存的是日期各个组成部分的数值表示

如果要转成字符串,调用format就可以了,输出格式就是SimpleDateFormat里指定的格式

比如String s = sdfformat(date); // sdf是SimpleDateFormat

获取当前时间以 年/月/日(如2008/12/6) 显示:

javasqlDate date=new javasqlDate(new javautilDate()getTime());

Systemoutprint(datetoString()replaceAll("-", "/"));

获取当前时间以 月/日/年(如12/6/2008) 显示:

javasqlDate date=new javasqlDate(new javautilDate()getTime());

Systemoutprint(dategetMonth()+"/"+dategetDay()+"/"+datetoString()substring(0,4));

这篇文章主要介绍了PHP使用GETDATE获取当前日期时间作为一个关联数组的方法,实例分析了php中GETDATE函数使用技巧,需要的朋友可以参考下

本文实例讲述了PHP使用GETDATE获取当前日期时间作为一个关联数组的方法。分享给大家供大家参考。具体分析如下:

PHP

GETDATE函数是用来获得当前的日期和时间,从 *** 作系统或一个关联数组转换成UNIX风格的日期整数。

语法格式如下

1

2

array

getdate

();

array

getdate

(integer

$Time);

参数如下:

Arguments

$Time

The

number

of

seconds

since

midnight

before

January

1,

1970

(UNIX

style)

Default

The

default

is

the

current

date

and

time

from

the

operating

system)

The

return

value

is

an

associative

array

containing:

mon

The

month

of

the

year

as

a

number

(112)

mday

The

day

of

the

month

(131)

year

The

year

(4

digits)

hours

The

hour

of

the

day

(023)

minutes

The

minutes

of

the

hour

(059)

seconds

The

seconds

of

the

minute

(059)

month

The

month

of

the

year

as

a

word

(JanuaryDecember)

yday

The

day

of

the

year

(0365)

wday

The

day

of

the

week

as

a

number

(06)

weekday

The

day

of

the

week

as

a

word

(SundaySaturday)

0

Seconds

since

midnight

before

January

1,

1970

下面是一个使用范例:

1

2

3

4

5

6

<php

$Now

=

getdate();

foreach

($Now

as

$Key

=>

$Value)

{

echo

"$Key

=>

$Valuen";

}

>

输出结果如下:

1

2

3

4

5

6

7

8

9

10

11

seconds

=>

59

minutes

=>

14

hours

=>

7

mday

=>

26

wday

=>

6

mon

=>

12

year

=>

2009

yday

=>

359

weekday

=>

Saturday

month

=>

December

0

=>

1261811699

希望本文所述对大家的php程序设计有所帮助。

用SimpleDateFormat这个类来获取当前系统时间 下面为例子程序

import javatextSimpleDateFormat;

import javautilDate;

public class Time {

public static void main(String[] args) {

SimpleDateFormat format = new SimpleDateFormat(

"yyyy年-M月-d日 kk时:m分:ss秒 E ");

String s = formatformat(new Date());

Systemoutprintln(s);

}

}

输出:2008年-7月-14日 21时:50分:02秒 星期一

首先获取你想要知道的Date——aDate;

NSDate aDate;

NSCalendar calendar=[NSCalendar currentCalendar];

NSDateComponents components=[calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:aDate];

NSInteger year=[components Year];

NSInteger month=[components Month];

NSInteger day=[components day];

注意:只能获取你声明的NSCalendarUnit的数据

NSDateFormatter dateFormater=[[NSDateFormatter alloc]init];

[dateFormater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString feedBackDate=[dateFormater stringFromDate:aNSDate];

以上就是关于String转Date类型 取当前时间全部的内容,包括:String转Date类型 取当前时间、java 获取java.sql.date类型的系统当前时间、PHP使用GETDATE获取当前日期时间作为一个关联数组的方法等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9715481.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存