⑴ android中Toast可以用毫秒设置显示时间吗
时间是固定的 2s~3.5s,你想要更短一点只能自定义,其余的没效果
⑵ Android:如何获取当前系统毫秒
Date dt= new Date();
Long time= dt.getTime();//这就是距离1970年1月1日0点0分0秒的毫秒数
DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间。日期/时间格式化子类(如 SimpleDateFormat)允许进行格式化(也就是日期 -> 文本)、解析(文本-> 日期)和标准化。将日期表示为 Date 对象,或者表示为从 GMT(格林尼治标准时间)1970 年 1 月 1 日 00:00:00 这一刻开始的毫秒数。
DateFormat 提供了很多类方法,以获得基于默认或给定语言环境和多种格式化风格的默认日期/时间 Formatter。格式化风格包括 FULL、LONG、MEDIUM 和 SHORT。方法描述中提供了使用这些风格的更多细节和示例。
DateFormat 可帮助进行格式化并解析任何语言环境的日期。对于月、星期,甚至日历格式(阴历和阳历),其代码可完全与语言环境的约定无关。
⑶ 如何将android时间戳转换成时间
时间戳就是如1377216000000 这种格式我们在mysql数据库中会经常用到把时间转换成时间戳或把时间戳转换成日期格式了,下面我来介绍安卓中时间戳操作转换方法。
一、原理
时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算。好~ 直接进入主题。(下面封装了一个类,有需要的同学可以参考或是直接Copy 就可以用了。)
如: 2013年08月23日 转化后是 1377216000000
二、步骤
1、创建 DateUtilsl类。
代码如下 复制代码
importjava.text.ParseException;
importjava.text.SimpleDateFormat;
importjava.util.Date;
/*
* @author Msquirrel
*/
public class DateUtils {
privateSimpleDateFormat sf = null;
/*获取系统时间 格式为:"yyyy/MM/dd "*/
public static String getCurrentDate() {
Date d = newDate();
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsf.format(d);
}
/*时间戳转换成字符窜*/
public static String getDateToString(long time) {
Date d = newDate(time);
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsf.format(d);
}
/*将字符串转为时间戳*/
public static long getStringToDate(String time) {
sdf = newSimpleDateFormat("yyyy年MM月dd日");
Date date = newDate();
try{
date = sdf.parse(time);
} catch(ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
returndate.getTime();
}
2、在对应使用的地方调用就可以了。
代码如下 复制代码
DateUtils.getCurrentDate(); //获取系统当前时间
DateUtils.getDateToString(时间戳); //时间戳转为时间格式
DateUtils.getStringToDate("时间格式");//时间格式转为时间戳
⑷ android中在编辑框怎样获取日期
这取决于对日期的格式定义
假如日期格式为2015-12-09即为2015年12月9日
可以使用SimpleDateFormat把字符串格式化转为日期
示例如下
{
privateEditTextetDate;
privateButtonbtn;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etDate=(EditText)findViewById(R.id.text);
btn=(Button)findViewById(R.id.button);
btn.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
Stringtxt=etDate.getText().toString();
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");
Datedate=sdf.parse(txt);
}
});
}
}
SimpleDateFormat的语法格式
G 年代标志符
y 年
M 月
d 日
h 时 在上午或下午 (1~12)
H 时 在一天中 (0~23)
m 分
s 秒
S 毫秒
E 星期
D 一年中的第几天
F 一月中第几个星期几
w 一年中第几个星期
W 一月中第几个星期
a 上午 / 下午 标记符
k 时 在一天中 (1~24)
K 时 在上午或下午 (0~11)
z 时区
⑸ android 日期时间使用哪个 calender date time
你说的是VBScript脚本语言吧 FormatDateTime(Date,vbShortDate)短日期格式:比如2005-11-30 FormatDateTime(Date,vbLongDate) 长日期格式:比如2005年11月30日 FormatDateTime(Time,vbShortTime) 短时间格式:比如19:02 FormatDateTime(Time,vbLongTime) 长时间格式:比如19:02:24
⑹ android 如何将yyyy-mm-dd hh:mm 转换成秒
1、用java中的Date类中的getTime()方法得到的是毫秒。
2、这种格式的你再看看SimpleDateFormat
⑺ Android 中的MediaStore
那就把秒数timeX1000转成毫秒longTime
再用Date date = new Date(longTime);
⑻ android开发 怎么把秒转换成时间
直接传入毫秒数作为参数,给Date对象就可以得到普通的时间了,然后通过getHours,getFullYear等方法获取年月日,时分秒:
DatenewTime=newDate(“传入毫秒”);//就得到普通的时间了
inthour=newTime.getHours();//就得到了小时
⑼ 安卓把毫秒变成日时分秒的格式
long a=System.currentTimeMillis();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
format.format(new Date(a));
日期格式字节根据需求改
⑽ android 如何获取当天23:59的毫秒数
您好:很高兴回答你的问题;
主要有以下两种办法:
方法一:
Date date=new Date();
String ss= ""+date.getTime();
Calendar c = Calendar.getInstance();
long l = c.getTimeInMillis();
方法二:
Date dt= new Date();
Long time= dt.getTime();
Long time2=System.currentTimeMillis();
这里提供了两种方式获取时间,但是如果想获取前一天的时间,用日历类实现即可。
我具体写了一下如何改变日期,希望有用。
public class Test02 {public static void main(String args[]) {Calendar c = Calendar.getInstance();System.out.println("昨天是:"+c.getTime());//System.out.println("今天是:"+c.get(Calendar.YEAR)+"年"+c.get(Calendar.MONTH+1)+"月"+c.get(Calendar.DAY_OF_YEAR)+"日");c.add(Calendar.DAY_OF_YEAR, -1);System.out.println("昨天是:"+c.getTime());//System.out.println("今天是:"+c.get(Calendar.YEAR)+"年"+c.get(Calendar.MONTH+1)+"月"+c.get(Calendar.DAY_OF_YEAR)+"日");long time1 = c.getTimeInMillis();long randtime=(long)(Math.random()*(long)Math.pow(10, 6));long time2 = c.getTimeInMillis()+randtime;System.out.println(time1 + "," + time2);}} 其中long randtime=(long)(Math.random()*(long)Math.pow(10, 6));是随机产生的一个值,如果你是一天中的时间段,是不是用这个值可以控制时间段的长度,知道开始时间和时间段长度就可以知道结束时间。
肯定行!希望能帮助你,望采纳,谢谢!