我想在今天的日期之前7天获取日期.我正在使用SimpleDateFormat来获取今天的日期.
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy");
Run Code Online (Sandbox Code Playgroud)
请指导我完成这个
我发现最有用的更新答案
SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");
String currentDateandTime = sdf.format(new Date());
Date cdate=sdf.parse(currentDateandTime);
Calendar now2= Calendar.getInstance();
now2.add(Calendar.DATE, -7);
String beforedate=now2.get(Calendar.DATE)+"/"+(now2.get(Calendar.MONTH) + 1)+"/"+now2.get(Calendar.YEAR);
Date BeforeDate1=sdf.parse(beforedate);
cdate.compareTo(BeforeDate1);
Run Code Online (Sandbox Code Playgroud)
谢谢你的回复
我正在使用SQLITE db在移动设备上更新数据库,该设备应该在服务器更新时更新它的数据库即wamp服务器.
任何人都可以建议我如何实现这一目标.
我不想读取整个服务器数据库,因为它会在读取整个数据库时增加数据使用量,仅用于单个更新或多个更新.更新在产品表中完成,只有价格字段由服务器端更新.
嗨,我正在开发一个应用程序,当从手机中删除耳机时生成一个事件.我用接收方法创建了一个广播接收器
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
Log.i("Broadcast Receiver", "Hello");
if( (action.compareTo(Intent.ACTION_HEADSET_PLUG)) == 0) //if the action match a headset one
{
int headSetState = intent.getIntExtra("state", 0); //get the headset state property
int hasMicrophone = intent.getIntExtra("microphone", 0);//get the headset microphone property
if( (headSetState == 0) && (hasMicrophone == 0)) //headset was unplugged & has no microphone
{
//do whatever
}
}
}
Run Code Online (Sandbox Code Playgroud)
调用此方法如下
IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
HeadSetBroadCastReceiver receiver …Run Code Online (Sandbox Code Playgroud) 嗨,我正在开发一个创建动态组件,如按钮等的应用程序.当某种情况发生时,我想删除或清空我的布局..任何人都可以指导或建议我吗?
由于更新之间的最短时间,它会在 1 秒后一次又一次地显示位置更新,一旦我获得位置更新,我该如何停止
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1000; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1*1000*60; // in Milliseconds
protected LocationManager locationManager;
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MINIMUM_TIME_BETWEEN_UPDATES,MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
private class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location location)
{
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude(),location.getTime()
);
Toast.makeText(MyService.this, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {}
public void onProviderDisabled(String s) {} …Run Code Online (Sandbox Code Playgroud) 我想从2D数组创建图像.我使用BufferImage概念来构造Image.but原始图像和构造图像之间存在差异由下面的图像显示


我使用以下代码
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
Run Code Online (Sandbox Code Playgroud)
/****@author pratibha*/
public class ConstructImage{
int[][] PixelArray;
public ConstructImage(){
try{
BufferedImage bufferimage=ImageIO.read(new File("D:/q.jpg"));
int height=bufferimage.getHeight();
int width=bufferimage.getWidth();
PixelArray=new int[width][height];
for(int i=0;i<width;i++){
for(int j=0;j<height;j++){
PixelArray[i][j]=bufferimage.getRGB(i, j);
}
}
///////create Image from this PixelArray
BufferedImage bufferImage2=new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
for(int y=0;y<height;y++){
for(int x=0;x<width;x++){
int Pixel=PixelArray[x][y]<<16 | PixelArray[x][y] << 8 | PixelArray[x][y];
bufferImage2.setRGB(x, y,Pixel);
}
}
File outputfile = new File("D:\\saved.jpg");
ImageIO.write(bufferImage2, "jpg", outputfile);
}
catch(Exception ee){
ee.printStackTrace();
}
}
public static void main(String args[]){
ConstructImage …Run Code Online (Sandbox Code Playgroud) 我在android中使用sqlite,我通过传递多个where子句获取结果,这给了我一个错误.单个where子句对我来说工作正常问题是多个where子句.建议我改变或找出我正在做的错误
带有查询的错误消息
ERROR/AndroidRuntime(837): Caused by: android.database.sqlite.SQLiteException:
no such column: Maharashtra:,while compiling: SELECT _id, r_shop FROM retailer
WHERE r_state = Maharashtra AND r_city = Thane AND r_region = Checknaka
String selection = MySQLiteHelper.STATE + " = Maharashtra"
+" AND " + MySQLiteHelper.CITY + " = Thane"
+" AND " + MySQLiteHelper.REGION + " = Checknaka";
Cursor cursor = database.query(MySQLiteHelper.RETAILER_TABLE,
new String[] {MySQLiteHelper.COLUMN_ID, MySQLiteHelper.SHOP }, selection,
null, null, null, null);
Run Code Online (Sandbox Code Playgroud) 我从320数字创建RGB .我得到以下
输出:
-16776896
Run Code Online (Sandbox Code Playgroud)
我写了这段代码
Color c=new Color(320);
System.err.println(c.getRGB());
System.out.println(c.getRed()+" "+c.getGreen()+" "+c.getBlue()+" "+c.getAlpha());
System.out.println(c.toString());
Run Code Online (Sandbox Code Playgroud)
现在我想从中回顾320价值-16776896.我该怎么办?
我想将二进制数转换为double.我有二进制字符串
1100000110011101010111011000101011011000011111111111111111111110
Run Code Online (Sandbox Code Playgroud)
我想将它转换为double值.我期待以下输出.
Output:-1.2316741412499997E8
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题