问题列表 - 第29704页

如何将以String格式保存的日期转换为日期格式

可能重复:
java中的DateFormat转换问题?

我试图将字符串转换为日期,但得到错误.

我正在使用日期:

URL xmlUrl = new URL(path);
URLConnection urlconn = xmlUrl.openConnection();
Date =  new Date(urlconn.getLastModified());
Run Code Online (Sandbox Code Playgroud)

然后我将此日期保存在一个文件中,该文件以下列格式保存:

Mon Jun 21 16:31:24 Asia/Karachi 2010
Run Code Online (Sandbox Code Playgroud)

然后当我稍后从文件中读取这个日期作为字符串时,我再次想要将它保存到日期,但我收到错误.

我试过了 :

DateFormat format = DateFormat.getDateInstance();
date =  format.parse(fileDate);
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

java.text.ParseException: Unparseable date: Mon Jun 21 16:31:24 Asia/Karachi 2010
Run Code Online (Sandbox Code Playgroud)

有什么方法可以找回日期.

谢谢

android date

0
推荐指数
1
解决办法
2万
查看次数

寻找一种更好的方法来排序我的List <T>

我正在审查我不久前写的一段代码,我只是讨厌我处理排序的方式 - 我想知道是否有人能够向我展示更好的方法.

我有一个类,Holding其中包含一些信息.我有另一个类,HoldingsList其中包含一个List<Holding>成员.我也有一个枚举,PortfolioSheetMapping它有大约40个左右的元素.

它看起来像这样:

public class Holding
{
    public ProductInfo Product {get;set;} 
    // ... various properties & methods ...
}

public class ProductInfo
{
    // .. various properties, methods... 
}

public class HoldingsList
{
    public List<Holding> Holdings {get;set;}
    // ... more code ...
}

public enum PortfolioSheetMapping
{
    Unmapped = 0,
    Symbol,
    Quantitiy,
    Price,
    // ... more elements ...
}
Run Code Online (Sandbox Code Playgroud)

我有一个方法可以调用List进行排序,具体取决于用户选择的枚举.该方法使用mondo switch语句,有超过40个案例(呃!).

下面的简短代码段说明了代码:

if (frm.SelectedSortColumn.IsBaseColumn)
{
    switch (frm.SelectedSortColumn.BaseColumn)
    {
        case PortfolioSheetMapping.IssueId: …
Run Code Online (Sandbox Code Playgroud)

c# .net-3.5 c#-3.0

7
推荐指数
1
解决办法
412
查看次数

Python:检查shutil.copyfile何时完成

我有这样的代码:

for file in file_list:
    shutil.copyfile(file,newpath)
#do further actions
Run Code Online (Sandbox Code Playgroud)

这是一个问题,在 #do further actions我使用复制的文件时,我需要确保shutil.copyfile函数完成他们的任务.我怎样才能确定这一点?

python shutil file-copying

7
推荐指数
1
解决办法
6276
查看次数

尝试在ASP.Net站点上使用Visual Studios Profiler时出现Metabase错误

我正在尝试在ASP.Net网站上运行性能向导.但是,每当我尝试启动它时,我都会收到以下错误.

"该网站包含意外信息,或者您无权访问元数据库.您必须是本地计算机上Administrators组的成员才能访问IIS matabase.因此,您无法创建或打开本地IIS网站.如果您具有文件所在文件夹的读取,写入和修改权限,您可以创建指向该文件夹的文件系统网站以继续"

我是我机器上的管理员.尝试使用谷歌搜索但没有得到任何东西.任何人以前都运行它并知道如何处理它?

c# asp.net profiling

48
推荐指数
3
解决办法
8541
查看次数

如何检索运行Windows服务的用户名?

给定一个服务名称,我想检索它运行的用户名(即服务属性窗口的"登录"选项卡中显示的用户名).类中似乎没有任何东西ServiceController可以检索这些基本信息.其他任何东西System.ServiceProcess看起来都不会暴露这些信息.有没有一个托管解决方案,或者我将不得不降低到更低级别的东西?

c# windows-services username

16
推荐指数
2
解决办法
2万
查看次数

使用不同的兼容类型覆盖属性

我需要一个带有属性的基类,在这里我可以派生具有相同属性但不同(兼容)类型的类.基类可以是抽象的.

public class Base
{
    public virtual object prop { get; set; }
}

public class StrBase : Base
{
    public override string prop { get; set; } // compiler error
}

public class UseIt
{
    public void use()
    {
        List<Base> l = new List<Base>();
        //...
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用Generics但是在使用该类时会给我一个问题,因为我想在List中存储不同类型的基类.

public class BaseG<T>
{
    public T prop { get; set; }
}

public class UseIt
{
    public void use()
    {
        List<BaseG> l = new List<BaseG>(); // requires type argument
        //...
    } …
Run Code Online (Sandbox Code Playgroud)

c# generics inheritance properties .net-2.0

18
推荐指数
3
解决办法
2万
查看次数

Ninject与ASP.Net webforms和MVC

我想在一个结合ASP.Net webforms和ASP.Net MVC的项目中使用Ninject.我正在使用Ninject 2,但是当我使用来自Ninject.Web.Mvc的NinjectHttpApplication时,当我使用类似于PageBase的东西而没有创建内核时,它就会抱怨.

我在Global.asax中有以下内容,我不确定要添加什么.

public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication
{
    protected override void OnApplicationStarted()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);
        RegisterAllControllersIn(Assembly.GetExecutingAssembly());
    }

    protected override Ninject.IKernel CreateKernel()
    {
        return new StandardKernel(new ServiceModule());
    }
}
Run Code Online (Sandbox Code Playgroud)

有人在某个地方工作,可以分享一些想法或代码吗?

asp.net asp.net-mvc webforms ninject

7
推荐指数
1
解决办法
1951
查看次数

为什么我收到一条错误消息,即.replace不是函数?

我有这个功能:

function countLitreKgSums(cProductIds){
  var cLitreKgSums = new Array();
  var cWeek = 0;
  for(i=0;i<cProductIds.length;i++){
    var cLitreKgSum = 0;
    $("#plan_table td[class='week']").each(function(){
            cWeek = $(this).html();
            var cLitreKgValue = $("input[name*='plan_table_week" + cWeek + "_prod" + cProductIds[i] + "_']").val();
            if (cLitreKgValue == "") {
                cLitreKgValue = 0;
            }
            cLitreKgValue = cLitreKgValue.replace(/,/g, '.').replace(/[^\d\.]/g, '').replace(/\s/g, '');
            cLitreKgValue = parseFloat(cLitreKgValue);
            cLitreKgSum += cLitreKgValue;
       });
       cLitreKgSum = Math.round(cLitreKgSum * 100) / 100;
       cLitreKgSums[i] = cLitreKgSum;
  }
  return cLitreKgSums;
  //console.log(cLitreKgSums);
}
Run Code Online (Sandbox Code Playgroud)

我收到错误信息,即.replace不是一个函数,但在其他函数中它可以正常工作.有什么不同?

javascript jquery replace function

12
推荐指数
2
解决办法
7万
查看次数

退出期望{}没有超时

我正在努力解决在ssh中自动输入密码的经典问题,就像其他人一样,我在黑暗中磕磕绊绊地期待着.最后,我拼凑了一个有点工作的脚本:

#!/usr/bin/expect -f

# command line args
set user_at_host [lrange $argv 0 0]
set password [lrange $argv 1 1]

set timeout 1

# ssh command
spawn ssh -S ~/.ssh/tmp.$user_at_host -M -N -f $user_at_host

# deal with ssh prompts
expect {
    "*yes/no*" { send "yes\r" ; exp_continue }
    "*assword:" { send "$password\r" ; exp_continue }
}
Run Code Online (Sandbox Code Playgroud)

此脚本仅timeout 1在线路上终止,没有它只是挂起,并且只能通过用户交互(^C)终止.

当该spawn行是一个直接的ssh命令时,脚本立即终止,但这不是你的直接ssh.可能不同的是-f使它在后台运行的选项(但我尝试了没有它的脚本无济于事).

我读过这个interact或者expect eof可能会有所帮助,但我找不到真正能做到的正确的咒语.

我的问题(我认为)是如何制作一个期望脚本,产生一个后台进程,终止没有超时?


编辑:我应该期望(没有双关语意)"使用无密码ssh身份验证"的答案.虽然这是一个合理的建议,但在我的场景中它并不是合适的解决方案:在可信环境中自动测试vanilla已安装的系统,其中不希望/可能向图像添加可信密钥.

ssh scripting expect

8
推荐指数
2
解决办法
2万
查看次数

如何WPF绑定书面内联=简短形式

我在表单中有大约100个TextBox.如果它们是十进制的,我需要验证它们.这有效,但它太冗长了,我不想在XAML中用800代替100行.

<TextBox.Text>
    <Binding Path="MyPath" UpdateSourceTrigger="PropertyChanged" Stringformat="{}{0:N}" NotifyOnValidationError="True">
        <Binding.ValidationRules>
            <myRulesNamespace:MyValidationRule ValidationType="decimal" />
        </Binding.ValidationRules>
    </Binding>
</TextBox.Text>
Run Code Online (Sandbox Code Playgroud)

有没有办法如何将它重写为这样的简短形式?:

Text="{Binding MyPath, UpdateSourceTrigger='PropertyChanged', StringFormat='{}{0:N}', NotifyOnValidationError=True, ValidationRules NOW WHAT?}"
Run Code Online (Sandbox Code Playgroud)

wpf binding

7
推荐指数
1
解决办法
930
查看次数