小编jap*_*hey的帖子

Javascript 检查数组中的项目是否连续

假设我有一个包含值 [1,2,3,6,7] 的数组。

如何检查数组是否包含 3 个连续的数字。例如,上面的数组包含 [1,2,3],因此这将在我的函数中返回 false。

        var currentElement = null;
        var counter = 0;

        //check if the array contains 3 or more consecutive numbers:
        for (var i = 0; i < bookedAppArray.length; i++) {
            if ((bookedAppArray[i] != currentElement) && (bookedAppArray[i] === bookedAppArray[i - 1] + 1)) {

                if (counter > 2) {
                    return true;
                }

                currentElement = bookedAppArray[i];
                counter++;
            } else {
                counter = 1;
            }
        }

        if(counter > 2){
            return true;
        } else{
            return false;
        }
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery

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

如何获得2个字符之间的值

我的ID为' 2015-11-30_1112_3 '.如何获取两个下划线(_)之间的值,所以我留下' 1112 '.

请注意,字符串的长度会有所不同.

javascript jquery

3
推荐指数
1
解决办法
1301
查看次数

Swift - 按属性获取数组中的对象

我是Swift的新手,我在按属性检索数组中的对象时遇到了一些问题.

请注意,我使用的是Swift 2.0.

我有以下数组;

//Dummy Data prior to database call:
static var listPoses = [
    YogaPose(id: 1, title: "Pose1", description: "This is a Description 1", difficulty: Enums.Difficulty.Beginner, imageURL: "Images/Blah1"),
    YogaPose(id: 2, title: "Pose2", description: "This is a Description 2", difficulty: Enums.Difficulty.Advanced, imageURL: "Images/Blah2"),
    YogaPose(id: 3, title: "Pose3", description: "This is a Description 3", difficulty: Enums.Difficulty.Intermediate, imageURL: "Images/Blah3"),
    YogaPose(id: 3, title: "Hello World", description: "This is a Description 3", difficulty: Enums.Difficulty.Intermediate, imageURL: "Images/Blah3")
] 
Run Code Online (Sandbox Code Playgroud)

我现在有一个方法,我想通过Id返回一个对象.有人可以建议我怎么做...例如listPose.Id === Id;

 //Returns a single YogaPose …
Run Code Online (Sandbox Code Playgroud)

arrays collections xcode object swift

3
推荐指数
1
解决办法
6412
查看次数

使用NSTimer的Swift进度视图

我有一个进度视图栏,我想用它来表示时间.这是我在Swift的第一个项目,我不确定如何解决这个问题.所以任何帮助/建议将不胜感激......

(使用Xcode 7.2和Swift 2.0)

下面是我的视图控制器.触发'btnPlaySession'时,视图控制器上的内容每20秒更改一次.当计时器计数到20时,id喜欢用进度条指示这个(因此每次内容改变时进度条都会重置).

class CreatedSessionViewController: UIViewController {

var createdSession: [YogaPose]!
var poseDuration: Double = 20.00 
var timer = NSTimer!()
var currentPoseIndex = 1

//Outlets:
@IBOutlet var poseProgressView: UIProgressView!
@IBOutlet var lblPoseCount: UILabel!
@IBOutlet var lblPoseName: UILabel!
@IBOutlet var imgPose: UIImageView!
@IBOutlet var tvDescription: UITextView!

// Do any additional setup after loading the view:
override func viewDidLoad() {
    super.viewDidLoad()

    displayFirstPoseInArray()
}

func displayFirstPoseInArray(){
    lblPoseCount.text = (String(currentPoseIndex) + "/" + String(createdSession.count))
    lblPoseName.text = createdSession[0].title
    imgPose.image = UIImage(named: String(format: "%d.jpg", (createdSession[0].id)!)) …
Run Code Online (Sandbox Code Playgroud)

nstimer uiprogressview nstimeinterval progress-bar swift

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

C# 将 DateTime 从 UTC 转换为 GMT 或 BST

我在 SQL 中存储日期时间,该日期时间是从 UTC 格式的 Azure 服务器检索的。

当我从 SQL 检索此日期时间时,日期时间类型未指定......

在英国,我们目前采用 BST,如何根据一年中的时间将从 SQL 收到的日期时间转换为 BST 或 GMT?

我的测试/生产服务器位于在 UTC 上运行的 Azure 中。

回答

感谢@jonathon,我想出了以下扩展方法来解决我的问题。

      public static DateTime CovertDateTimeToDateTimeGmt(this DateTime source)
    {
        var sourceUtc = DateTime.SpecifyKind(source, DateTimeKind.Utc);
        var destinationTimezoneId = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
        var sourceLocalTime = TimeZoneInfo.ConvertTimeFromUtc(sourceUtc, destinationTimezoneId);
        return sourceLocalTime;
    }
Run Code Online (Sandbox Code Playgroud)

因为我从 SQL 接收的日期时间没有指定日期时间类型,所以我首先将其转换为指定类型的新日期时间。

c# datetime utc gmt

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